Sign inSign up

toolkitbox/postgres

By toolkitbox

•Updated 18 days ago

DevOps toolkit - postgres client

Image
0

2.3K

toolkitbox/postgres repository overview

⁠PostgreSQL Client

GitHub Stars GitHub Issues Docker Pulls

📢 Found an issue or want to request a new tool? Open an issue on GitHub⁠

Command line client for PostgreSQL.

⁠Quick Start

⁠Docker
# Interactive mode
docker run -it --rm \
  -e PGPASSWORD=my_password \
  ghcr.io/pabpereza/toolkitbox/postgres:latest \
  psql -h my-server.com -U postgres -d my_database

# Run single query
docker run --rm \
  -e PGPASSWORD=my_password \
  ghcr.io/pabpereza/toolkitbox/postgres:latest \
  psql -h my-server.com -U postgres -d my_database -c "SELECT version();"
⁠Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: postgres-client
spec:
  containers:
  - name: postgres-client
    image: ghcr.io/pabpereza/toolkitbox/postgres:latest
    command: ["sleep", "infinity"]
    env:
    - name: PGHOST
      value: "postgres-service"
    - name: PGUSER
      value: "postgres"
    - name: PGPASSWORD
      valueFrom:
        secretKeyRef:
          name: postgres-credentials
          key: password
    - name: PGDATABASE
      value: "mydb"

⁠Description

PostgreSQL Client includes psql, the interactive terminal tool for PostgreSQL, along with additional utilities like pg_dump, pg_restore, and pg_isready. It allows you to execute SQL queries, manage databases, and perform backups.

⁠Installation

This component installs postgresql-client from the Alpine Linux repositories.

⁠Basic Usage

⁠Connect to a server
psql -h hostname -U user -d database
⁠Connect using URI
psql "postgresql://user:password@hostname:5432/database"
⁠Execute direct query
psql -h hostname -U user -d database -c "SELECT * FROM table"
⁠Execute SQL script
psql -h hostname -U user -d database -f script.sql
⁠Export database (backup)
pg_dump -h hostname -U user database > backup.sql
⁠Export in custom format (compressed)
pg_dump -h hostname -U user -Fc database > backup.dump
⁠Restore backup
pg_restore -h hostname -U user -d database backup.dump
⁠Check connectivity
pg_isready -h hostname -p 5432

⁠Useful psql Commands

-- List databases
\l

-- Connect to another database
\c database_name

-- List tables
\dt

-- Describe table
\d table_name

-- List users
\du

-- Show command help
\?

-- Execute system command
\! ls -la

-- Quit
\q

⁠Common Options

OptionDescription
-h, --hostServer to connect to
-p, --portPort (default: 5432)
-U, --usernameConnection user
-d, --dbnameDatabase to select
-c, --commandExecute SQL command and exit
-f, --fileExecute commands from file
-W, --passwordForce password prompt

⁠Environment Variables

VariableDescription
PGHOSTServer host
PGPORTServer port
PGUSERConnection user
PGPASSWORDPassword (not recommended in production)
PGDATABASEDefault database

⁠Available Legacy Versions

  • v9.6 - PostgreSQL 9.6
  • v10 - PostgreSQL 10
  • v11 - PostgreSQL 11

⁠Official Documentation

Tag summary

Content type

Image

Digest

sha256:dd27b3eed…

Size

11.6 MB

Last updated

18 days ago

docker pull toolkitbox/postgres