Quick & Dirty Guide to PostgreSQL
|
|
Introduction
Windows Setup
Watch out for issues when installing PG:
- It runs as an "unprivileged" user in unix terms, and given
the complex permissions model on Windows and the wide variety of setups
on machines that's not always proved easy to get right.
- If an AV is running on the server, tell the scanner that PG is a safe
application. Better option: Don't install an AV on the server...
Linux Setup
- Create a directory where PostgreSQL data will live: mkdir -p /var/pgsql/data
- Create a user account that will be used by PGSQL to run: useradd -c
"PostgreSQL account" -d /var/pgsql/data postgres
- Remove all unnecessary files copied by useradd: rm -f /var/pgsql/data
*; rm -Rf /var/pgsql/data/* ; rm -Rf /var/pgsql/data/.*
- Change ownership: chown -R postgres.postgres /var/pgsql
- Install postgresql-7.0.3-8.i386.rpm, postgresql-7.0.3-8.i386.rpm, and
postgresql-devel-7.0.3-8.i386.rpm
- su - postgres
- initdb -D /var/pgsql/data/
- postmaster -D /var/pgsql/data/ < /dev/null >> /var/pgsql/data/server.log
2>&1 &
- Add a startup script in /etc/rc.d/init.d/ so that PostgreSQL starts
automatically
- Create a dummy database, and log to psql: createdb testdb ; psql testdb;
(\q to exit)
Basic commands
Creating users
create user jdoe with password 'secret';
Changing a user's password
alter user jdoe with password 'admirer';
Assigning a user to a group
insert into pg_group (groname, grosysid, grolist) values ('posthackers',
'1234', '{5443, 8261}'); grant insert on foo to group posthackers;
Deleting a user
drop user jdoe;
Creating databases
(from the OS shell) createdb testdb;
(within PostgreSQL) create database testdb;
Deleting databases
(from the OS shell) dropdb testdb (within a PostgreSQL session) drop database
testdt;
Resources