This is a quick reference guide for how to edit settings via the terminal command line.
To download a pdf copy of each OS
Windows Cheatsheet
Mac OS Cheatsheet
Starting/Stopping the Server
Refer to: http://www.postgresql.org/docs/9.0/interactive/app-pg-ctl.html
Mac OS X
- Open Terminal
- Type su - postgres
- Type pg_ctl start or pg_ctl stop or pg_ctl restart
- - 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
- (Optional) Leave the terminal window open to view stderr log messages as you execute queries against the server.
Windows
- Open Control Panel
- Open Administrative Tools
- Open Services
- Find the PostgreSQL Server service
- Start, Stop or Restart the service
Reloading Changes to the Configuration File
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.
Mac OS X
- Open Terminal
- Type su - postgres
- Type pg_ctl reload
Windows
- Open Command Prompt
- Go to C:\Program Files\PostgreSQL\9.0\bin (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd PostgreSQL - enter - cd 9.0 enter - cd bin - enter
- pg_ctl reload
Backing Up A Database

|
Uncompressed backups from this point forward will use the .sql extenstion, while compressed backups will use the .backup extension.
|
Mac OS X - Uncompressed
- Open the terminal
- Type su - postgres
- Type pg_dump -o [DatabaseName] > [Path] e.g For Database 'Demo' -> pg_dump -o Demo > /Users/Shared/MyBackups/Demo.sql
Mac OS X - Compressed
- Open Terminal
- Type su - postgres
- 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
Windows - Uncompressed
- Open Command Prompt
- Go to C:\Program Files\PostgreSQL\9.0\bin (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd PostgreSQL - enter - cd 9.0 enter - cd bin - enter
- pg_dump -U postgres -o [DatabaseName] > [Path] e.g For Database 'Demo' -> pg_dump -U postgres -o Demo > /Users/Shared/MyBackups/Demo.sql
Windows - Compressed
- Open Command Prompt
- Go to C:\Program Files\PostgreSQL\9.0\bin (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd PostgreSQL - enter - cd 9.0 enter - cd bin - enter
- pg_dump -U postgres -o -F c -Z 9 [DatabaseName] > [Path] e.g For Database 'Demo' -> pg_dump -U postgres -o -F c -Z 9 Demo > /Users/Shared/MyBackups/Demo.backup
Windows - Compressed (via pgAdmin on a different machine then the server)
- Open Command Prompt
- Go to C:\Program Files\pgAdmin III\1.12 (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd pgAdmin III - enter - cd 1.12 enter
- pg_dump --host [IP address of server] --port 5432 --username "postgres" --format=c --compress=9 --file "C:\BoxOffice\[DatabaseBackupName].backup [DatabaseName] e.g For Database 'Demo' -> pg_dump --host 192.168.0.3 --port 5432 --username "postgres" --format=c --compress=9 --file "C:\BoxOffice\Demo.backup" Demo
Restoring a Database
Mac OS X - Uncompressed
- Open Terminal
- Type su - postgres
- Drop the existing database (If it exists)
- Create a new database with the same name
- Type psql [DatabaseName] psql Demo
Mac OS X - Compressed
- Open Terminal
- Type su - postgres
- Drop the existing database (If it exists)
- Create a new database with the same name
- Type pg_restore -d [DatabaseName] [Path] e.g for Database 'Demo' -> pg_restore -d Demo /Users/Shared/MyBackups/Demo.backup
Windows - Uncompressed
- Open Command Prompt
- Go to C:\Program Files\PostgreSQL\9.0\bin (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd PostgreSQL - enter - cd 9.0 enter - cd bin - enter
- Type psql -U postgres [DatabaseName] psql -U postgres Demo
Windows - Compressed
- Open Command Prompt
- Go to C:\Program Files\PostgreSQL\9.0\bin (Do cd.. to get back to C: prompt then type cd "Program Files" - enter - cd PostgreSQL - enter - cd 9.0 enter - cd bin - enter
- Type pg_restore -U postgres -d [DatabaseName] [Path] e.g for Database 'Demo' -> pg_restore -U postgres -d Demo /Users/Shared/MyBackups/Demo.backup