Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Last active September 10, 2024 11:51
Show Gist options
  • Save isabellachen/d5aa2221c3af319a30564235bcdf4894 to your computer and use it in GitHub Desktop.
Save isabellachen/d5aa2221c3af319a30564235bcdf4894 to your computer and use it in GitHub Desktop.
How to get up and running with postgres

Get up and running with Postgres sql

brew install postgresql

Make sure Postgres is installed by checking what version is installed

postgres -V

Start up Postgres

brew services start postgresql

When you're done for the day, remember to stop the process

brew services stop postgresql

Get onto the postgres sql command line

psql postgres

To find the connection info, database, user, socket and port

 postgres=# \conninfo

You should see the postgres prompt postgres=#, use the prompt to see what users are installed. This command executes and SQL query that gets all the users in the databse.

postgres=# \du

List all the databases

postgres=# \list

Create a database using the superuser account. Unrecommended in a real development scenario. CREATED DATABASE is a direct sql command, so don't forget the semicolon at the end.

postgres=# CREATE DATABASE  mymessages;

To drop the database

postgres=# DROP DATABASE mymessages;

To use the database you just created, you need to connect to it

postgres=# \connect mymessages

To list the tables in the currently connected database

postgres=# \dt

To quit

postgres=# \q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment