Skip to main content

Gotthard is a command line tool to simplify connecting to a PostgreSQL instance via a bastion host. This tool is created in the context of zalando-stups, however it could be used without it.

Installation

$ sudo pip3 install --upgrade gotthard

Configuration

Gotthard does not have its own configuration. It uses the piu configuration file.

Usage

Gotthard can provide help with the commands itself:

$ gotthard --help

Gotthard can run in two basic modes: in the foreground and in the background.

When running in the background, gotthard establishes a tunnel and keeps the tunnel running in the background.

$ gotthard shipping.logistics.db.example.com

When running in the foreground, the tunnel is established and the command you specify is executed. Once your command finishes, the tunnel is closed. If you need to pass options to the command, you will have to add the -- to signify that the following options should not be interpreted by gotthard.

$ gotthard shipping.logistics.db.example.com psql
$ gotthard shipping.logistics.db.example.com -- psql -U myusername

Stups: Requesting access to odd

When using even & odd, the command will only succeed if you have been granted access to the odd host you are trying to connect to. You can request access manually, but you can also have gotthard take care of this. When specifying a reason, gotthard will actually execute a piu request-access for you.

$ gotthard shipping.logistics.db.example.com --reason="Investigating INCIDENT-123" psql

Connecting to a local Spilo

If you want to connect to a Spilo that is running in the same network as your odd-host, you can use the name of the Spilo appliance to connect. This does however require you to be logged in to your AWS account, as we need to query your account.

$ gotthard shippinglogistics psql

How does it actually work

The way Gotthard works is by setting up an ssh tunnel to the bastion host. It chooses the local port specified a free local port to tunnel the requests to remote side to port 5432.

When running in the background, it’s task is done: It will report back the details of the tunnel.

When running in the foregroed, Gotthard will export the PostgreSQL related Environment Variables to the process it needs to run. Most PostgreSQL client tools will use these environment variables to connect, most of your python or perl scripts should adhere to these variables as well.

$ gotthard shippinglogistics env | grep PG
PGUSER=username
PGHOST=localhost
PGDATABASE=postgres
PGPORT=52296
PGSSLMODE=require

Examples

Export a database

$ gotthard shipping.logistics.db.example.com --reason="FEATURE-123" -- pg_dump -d fancydb -Fc -f fancydb.dump

Get the size of an RDS database

$ query="SELECT pg_database_size(CURRENT_CATALOG)"
$ gotthard example.us-west-2.rds.amazonaws.com -- psql -U rds_admin -d featuredb -c "$query"

Duplicate a Spilo database to your machine

This actually requires you to have replication privileges.

$ gotthard shippinglogistics -- pg_basebackup -D /postgres/mydata

Release files for gotthard 1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gotthard 1.11
File Size Uploaded
gotthard-1.11.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gotthard 1.11
File Interpreter ABI Platform
gotthard-1.11-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / gotthard-1.11.tar.gz

Download URL gotthard-1.11.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
76f62e3994d4e361216247597e586a5550360948ad193d0c04bdd388f46f89d5
BLAKE2b-256 checksum
How to use checksums
d31e0f4d69550a0261af3ddd667662099dec272f202d9503f08c3bfe9684430a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release files / gotthard-1.11-py3-none-any.whl

Download URL gotthard-1.11-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
013d950f310be33e1c9b6a98760eb19500453fe196b3770706330f8017d8e92f
BLAKE2b-256 checksum
How to use checksums
5ff8c988eb38ca3bf71d25b68d2fc500873b307bfacba3781e9fd75436534308
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

1.11 This release

2 release files

1.10

2 release files

0.10

2 release files

0.9

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page