PSQL command from Alpine containner

Twenty Four O Clock
2 min readOct 31, 2020
### exec to alpine containner
docker exec -it nifty_dubinsky sh
###alpine install psql
apk add postgresql-client
### connect to postgres
psql -h host -d database -U user -W
###Example
psql -U doadmin -p 25060 -h postgres-db-cluster-do-user-8157246-0.b.db.ondigitalocean.com logback -W
### when connected postgres require your enter password
Password for user doadmin:
## when password valid you can use sql command to interactive with postgres server
psql (12.4)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
### \l = list database
logback=> \l
####\c dbname = switch database
### Ex \c defaultdb
### Ex \c logback
### \dt = list table on current database
logback=> \dt
List of relations
Schema | Name | Type | Owner
--------+-------------------------+-------+---------
public | logging_event | table | doadmin
public | logging_event_exception | table | doadmin
public | logging_event_property | table | doadmin
(3 rows)
### \d table_name = describe table
logback=> \d logging_event
Table "public.logging_event"
Column | Type | Collation | Nullable | Default
-------------------+------------------------+-----------+----------+-------------------------------------------
timestmp | bigint | | not null |
formatted_message | text | | not null |
logger_name | character varying(254) | | not null |
level_string | character varying(254) | | not null |
thread_name | character varying(254) | | |
reference_flag | smallint | | |
arg0 | character varying(254) | | |
arg1 | character varying(254) | | |
arg2 | character varying(254) | | |
arg3 | character varying(254) | | |
caller_filename | character varying(254) | | not null |
caller_class | character varying(254) | | not null |
caller_method | character varying(254) | | not null |
caller_line | character(4) | | not null |
event_id | bigint | | not null | nextval('logging_event_id_seq'::regclass)

### \dn = list available schema
### \df = list available function
### \dv = list available views
### \du = list users and roles

### select version(); = print postgres version
### \g = executes previous command again
### \s = command history
### \s filename = save command history to file
### \i filename = execute psql command from file
### \? get help on psql
### ex show help alter table command
\h ALTER TABLE
### \timing = turn on query execution time
### \q = Quit psql

--

--