Skip to content

Instantly share code, notes, and snippets.

@shu-yusa
Created November 9, 2017 09:21
Show Gist options
  • Save shu-yusa/c52e89d23fe876a0326948afff6ee39f to your computer and use it in GitHub Desktop.
Save shu-yusa/c52e89d23fe876a0326948afff6ee39f to your computer and use it in GitHub Desktop.

Use PostgreSQL in mac using docker

Create docker container.

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

Install postgresql client into mac.

brew install postgresql

Connect to postgresql.

psql -h 127.0.0.1 -U postgres

end enter password mysecretpassword.

List databases.

postgres=# \l

Create a database.

create database database_name;

Delete a database.

postgres=# drop database database_name;

Select a database.

postgres=# \c database_name

Create a table.

postgres=# create table table_name (column_name1 column_type, column_name22 column_type);

Example of creating a database.

postgres=# create table test_table(id integer, name varchar(20);

List tables.

postgres=# \dt

Show table schema

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