Skip to content

Instantly share code, notes, and snippets.

@linxuedong
Created September 12, 2017 05:24
Show Gist options
  • Save linxuedong/5a1083efd8884799d01a3c9853f80951 to your computer and use it in GitHub Desktop.
Save linxuedong/5a1083efd8884799d01a3c9853f80951 to your computer and use it in GitHub Desktop.
docker postgres mantains 删除数据库结构

Attach to a docker container

docker exec -it project_postgres_1 bash

Switch to postgres user

root@58a96e78e770:/# su postgres
$

Enter to psql

$ psql
psql (9.6.3)
Type "help" for help.

postgres=#

List databases

postgres-# \l
                                   List of databases
     Name      |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
---------------+----------+----------+------------+------------+-----------------------
 project_name  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 postgres      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0     | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
               |          |          |            |            | postgres=CTc/postgres
 template1     | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
               |          |          |            |            | postgres=CTc/postgres
(4 rows)

postgres-#

Remove a db

drop database project_name;

create a db

create database project_name;

Connect to a database

postgres-# \c project_name
You are now connected to database "project_name" as user "postgres".
project_name-#

List tables

project_name-# \t
Tuples only is on.
project_name-#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment