用于隧道 PostgreSQL 连接的命令行实用程序
项目描述
Gotthard是一个命令行工具,用于简化通过堡垒主机连接到PostgreSQL实例。此工具是在zalando-stups的背景下创建的,但它也可以在没有它的环境中使用。
安装
$ sudo pip3 install --upgrade gotthard
配置
Gotthard 没有它自己的配置。它使用piu 配置文件。
使用
Gotthard 可以自行提供帮助命令。
$ gotthard --help
Gotthard 可以以两种基本模式运行:前台和后台。
在后台运行时,Gotthard 建立隧道并保持隧道在后台运行。
$ gotthard shipping.logistics.db.example.com
在前台运行时,会建立隧道并执行指定的命令。一旦命令执行完毕,隧道就会关闭。如果您需要向命令传递选项,您需要添加--来表示以下选项不应由 Gotthard 解释。
$ gotthard shipping.logistics.db.example.com psql
$ gotthard shipping.logistics.db.example.com -- psql -U myusername
Stups:请求访问odd
当使用偶数和奇数时,如果已授予您连接到要连接的奇数主机的访问权限,则命令将成功。您可以手动请求访问权限,也可以让 Gotthard 处理此事。在指定原因时,Gotthard 实际上会为您执行piu request-access。
$ gotthard shipping.logistics.db.example.com --reason="Investigating INCIDENT-123" psql
连接到本地Spilo
如果您想连接到与您的奇数主机在同一网络中运行的 Spilo,您可以使用 Spilo 设备的名称来连接。但这确实需要您登录到您的 AWS 账户,因为我们需要查询您的账户。
$ gotthard shippinglogistics psql
它是如何实际工作的
Gotthard 的工作方式是通过设置到堡垒主机的 ssh 隧道。它会选择一个指定的本地端口,并将请求隧道到远程端口的 5432。
在后台运行时,它的任务就完成了:它将返回隧道的详细信息。
在前台运行时,Gotthard 将 PostgreSQL 相关的 环境变量 导出给需要运行的过程。大多数 PostgreSQL 客户端工具将使用这些环境变量进行连接,大多数 Python 或 Perl 脚本也应该遵守这些变量。
$ gotthard shippinglogistics env | grep PG
PGUSER=username
PGHOST=localhost
PGDATABASE=postgres
PGPORT=52296
PGSSLMODE=require
示例
导出数据库
$ gotthard shipping.logistics.db.example.com --reason="FEATURE-123" -- pg_dump -d fancydb -Fc -f fancydb.dump
获取RDS数据库的大小
$ query="SELECT pg_database_size(CURRENT_CATALOG)"
$ gotthard example.us-west-2.rds.amazonaws.com -- psql -U rds_admin -d featuredb -c "$query"
将Spilo数据库复制到您的机器上
这实际上需要您拥有复制权限。
$ gotthard shippinglogistics -- pg_basebackup -D /postgres/mydata
项目详情
下载文件
下载您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。
源分布
构建分布
gotthard-1.11.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 76f62e3994d4e361216247597e586a5550360948ad193d0c04bdd388f46f89d5 |
|
MD5 | daa3a6266001f878217d60c135fd78db |
|
BLAKE2b-256 | d31e0f4d69550a0261af3ddd667662099dec272f202d9503f08c3bfe9684430a |
gotthard-1.11-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 013d950f310be33e1c9b6a98760eb19500453fe196b3770706330f8017d8e92f |
|
MD5 | f8f21049e4558aad0101c801e383ca19 |
|
BLAKE2b-256 | 5ff8c988eb38ca3bf71d25b68d2fc500873b307bfacba3781e9fd75436534308 |