Difference between revisions of "DB/Postgres PostgreSQL"

From Ever changing code
< DB
Jump to navigation Jump to search
(Created page with "* [https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/ Managing PostgreSQL users and roles] 04 MAR 2019, AWS Blog")
 
Line 1: Line 1:
* [https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/ Managing PostgreSQL users and roles]  04 MAR 2019, AWS Blog
* [https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/ Managing PostgreSQL users and roles]  04 MAR 2019, AWS Blog
= Cli client =
<source lang=bash>
# Install
apt-get install -yq postgresql-client
# Connect
export POSTGRES_DB=postgres
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=mypassword
psql -h localhost -p 5432 -U postgres postgres
psql (12.3 (Debian 12.3-1.pgdg100+1))
Type "help" for help.
postgres=#
  \l  -- list all databases
  \dt -- list all the tables in the current database
  \c mydatabase  -- switch database
  \d <table_name> -- describe a table
  \g -- execute previous command
  \? -- help
  \h DROP TABLE -- help about particular comamnd
  \timing -- execution times of queries
# Show version
postgres=# SELECT version();
                                                    version                                                     
------------------------------------------------------------------------------------------------------------------
PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
(1 row)
</source>

Revision as of 11:06, 18 November 2021

Cli client

# Install
apt-get install -yq postgresql-client

# Connect
export POSTGRES_DB=postgres
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=mypassword

psql -h localhost -p 5432 -U postgres postgres
psql (12.3 (Debian 12.3-1.pgdg100+1))
Type "help" for help.

postgres=#
  \l  -- list all databases
  \dt -- list all the tables in the current database
  \c mydatabase   -- switch database
  \d <table_name> -- describe a table
  \g -- execute previous command
  \? -- help
  \h DROP TABLE -- help about particular comamnd
  \timing -- execution times of queries

# Show version
postgres=# SELECT version();
                                                     version                                                      
------------------------------------------------------------------------------------------------------------------
 PostgreSQL 12.3 (Debian 12.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
(1 row)