How to administer PostGreSQL services, including users and databases.
PostGreSQL Server Admin Commands
- Restart the PostGreSQL server:
% sudo /usr/local/etc/rc.d/postgresql restart
- postgres is the PostgreSQL server.
% sudo /usr/local/bin/postgres --help
- psql is the PostgreSQL interactive terminal.
% sudo /usr/local/bin/psql --help
- Perform all administrative tasks as the pgsql user:
[tethys] ~% sudo su pgsql
$ whoami
pgsql
$
- Create a new superuser. -P means assign a [p]assword to the role, -E means [e]ncrypt stored password.
$ /usr/local/bin/createuser -PE cwmiller
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
$
- Create a new unprivileged user. -P means assign a [p]assword to the role, -E means [e]ncrypt stored password.
$ /usr/local/bin/createuser -PE chomicki
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
$
- Drop a user:
$ /usr/local/bin/dropuser chomicki
- Perform all administrative tasks as the pgsql user:
[tethys] ~% sudo su pgsql
$ whoami
pgsql
$
- Create a database (name it with the user's username, because that's what Postgres looks for by default):
$ /usr/local/bin/createdb cwmiller
Grant or Revoke Privileges:
- http://www.postgresql.org/docs/8.4/interactive/index.html
- http://wiki.postgresql.org/
- http://wiki.postgresql.org/wiki/Frequently_Asked_Questions