Arts Management Systems
Cheat Sheet http://www.artsman.com
© 2011, Arts Management Systems
PostgreSQLTerminalCommandsMACOS
Starting/StoppingtheServer
Refer to: http://www.postgresql.org/docs/9.0/interactive/app-pg-ctl.html
1. Open Terminal
2. Type su - postgres
3. Type pg_ctl start or pg_ctl stop or pg_ctl restart
4. or - you may need to enter the full pathname of postgresql bin's folder including the location of the data folder if the PATH
environment variables are set incorrectly. As in:
/Library/PostgreSQL/9.0/bin/pg_ctl start -D /Library/PostgreSQL/9.0/data
/Library/PostgreSQL/9.0/bin/pg_ctl stop -D /Library/PostgreSQL/9.0/data
5. (Optional) Leave the terminal window open to view stderr log messages as you execute queries against the server.
ReloadingChangestotheConfigurationFile
Refer to: http://www.postgresql.org/docs/9.0/interactive/app-pg-ctl.html - simply sends the postgres process a SIGHUP signal, causing
it to reread its configuration files (postgresql.conf, pg_hba.conf, etc.). This allows changing of configuration-file options that do not
require a complete restart to take effect.
1. Open Terminal
2. Type su - postgres
3. Type pg_ctl reload
BackingUpADatabase
Uncompressed backups from this point forward will use the .sql extenstion, while compressed backups will use the .backup
extension.
MacOSXUncompressed
1. Open the terminal
2. Type su - postgres
3. Type pg_dump -o [DatabaseName] > [Path] e.g For Database 'Demo' -> pg_dump -o Demo >
/Users/Shared/MyBackups/Demo.sql
MacOSXCompressed
1. Open Terminal
2. Type su - postgres
3. Type pg_dump -F c -Z 9 [DatabaseName] > [Path] e.g For Database 'Demo' -> pg_dump -F c -Z 9 Demo >
/Users/Shared/MyBackups/Demo.backup
RestoringaDatabase
MacOSXUncompressed
1. Open Terminal
2. Type su - postgres
3. Drop the existing database (If it exists)
4. Create a new database with the same name
5. Type psql [DatabaseName] < [Path] e.g for Database 'Demo' -> psql Demo < /Users/Shared/MyBackups/Demo.sql
Arts Management Systems
Cheat Sheet http://www.artsman.com
© 2011, Arts Management Systems
MacOSXCompressed
1. Open Terminal
2. Type su - postgres
3. Drop the existing database (If it exists)
4. Create a new database with the same name
5. Type pg_restore -d [DatabaseName] [Path] e.g for Database 'Demo' -> pg_restore -d Demo
/Users/Shared/MyBackups/Demo.backup