From 15fe042798c56bbc6a33c3a96bb32eaae29ea2ff Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Mon, 8 Apr 2024 18:14:38 +0200 Subject: [PATCH] chore(kb/postgresql): improve tl;dr --- .vscode/settings.json | 1 + knowledge base/postgresql.md | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c232b4a..8c21898 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -188,6 +188,7 @@ "posix", "poweroff", "powersave", + "psql", "pstate", "pulumi", "pvresize", diff --git a/knowledge base/postgresql.md b/knowledge base/postgresql.md index 22fbafc..feb169d 100644 --- a/knowledge base/postgresql.md +++ b/knowledge base/postgresql.md @@ -4,7 +4,7 @@ 1. [TL;DR](#tldr) 1. [Further readings](#further-readings) -1. [Sources](#sources) + 1. [Sources](#sources) ## TL;DR @@ -13,31 +13,45 @@ brew install 'postgresql@14' sudo dnf install 'postgresql' 'postgresql-server' sudo zypper install 'postgresql15' 'postgresql15-server' +``` +```sh # Connect to servers via CLI client. -psql --host "${HOSTNAME:-localhost}" --port "${PORT:-5432}" \ - "${DATABASENAME:-root}" "${USERNAME:-root}" +# If not given: +# - the hostname defaults to 'localhost'; +# - the port defaults to '5432'; +# - the username defaults to the current user. +psql 'my-db' +psql 'my-db' 'user' +psql 'postgresql://host:5433/my-db?sslmode=require' +psql -U 'username' -d 'my-db' -h 'hostname' -p 'port' -W 'password' + +# List available databases. +psql … --list + +# Execute commands. +psql 'my-db' … -c 'select * from tableName;' -o 'out.file' +psql 'my-db' … -c 'select * from tableName;' -H +psql 'my-db' … -f 'commands.sql' ``` ## Further readings - [Docker image] -## Sources - -All the references in the [further readings] section, plus the following: +### Sources +- [psql] - [Connect to a PostgreSQL database] + [docker image]: https://github.com/docker-library/docs/blob/master/postgres/README.md - - -[further readings]: #further-readings +[psql]: https://www.postgresql.org/docs/current/app-psql.html [connect to a postgresql database]: https://www.postgresqltutorial.com/connect-to-postgresql-database/