Skip to content

Instantly share code, notes, and snippets.

@mmwtsn
Last active August 7, 2023 07:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmwtsn/a2eea21f03e579528298 to your computer and use it in GitHub Desktop.
Save mmwtsn/a2eea21f03e579528298 to your computer and use it in GitHub Desktop.
A list of commands for navigating PostgreSQL.

PostgreSQL Cheatsheet

Helpful Commands

Start/Stop Launch Agent

launchctl unload ~/Library/LaunchAgents/org.postgresql.postgres.plist
launchctl load ~/Library/LaunchAgents/org.postgresql.postgres.plist

Common Commands

mysql: SHOW TABLES postgresql: \d postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

mysql: SHOW DATABASES postgresql: \l postgresql: SELECT datname FROM pg_database;

mysql: SHOW COLUMNS postgresql: \d table postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

mysql: DESCRIBE TABLE postgresql: \d+ table postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

Dokku + PostgreSQL + Rails

Documentation of Headaches

I attempted to push an existing Rails 4.1.4 application to an Ubuntu 14.04 Cloud server on SoftLayer this week. Here were all of the things that went wrong.

Database encoding: once everything was setup, Postgres was complaining that my database encoding (UTF-8) was not gelling with the SQL_ASCII encoding. Make sure you have console access before moving on:

Postgre console access: I was unable to access the console out of the box using dokku postgresql:console <APP_NAME>. A brief warning was returned suggesting that the postgresql-client wasn't installed as it could not find the psql executable. This one actually has nothing to do with Dokku or Docker: sudo apt-get install postgres-client.

Rebuild Template1: It turns out the encoding error came from Postgres attempting to build a new table from one of the default templates that provided the incorrect encoding. This answer came by way of Stack Overflow.

Postgres role: I had attempted to inherit the local role and run the production database under the app name as suggested on Digital Ocean. Unfortunately, Dokku runs as the root user. Simply update your production username value to root.

http://stackoverflow.com/a/16737776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment