我有一個帶有 PostgreSQL 的 Docker 容器,我想做一個pg_dump我的資料庫。我嘗試使用以下代碼:
client = docker.from_env()
postgres = client.containers.get('my_postgres')
command = 'pg_dump --dbname=postgresql://my_user:mypassword@localhost:5432/my_db -Fc > /var/lib/postgresql/data/dumps/test.sql'
log = postgres.exec_run(command, stdout=True, stderr=True)
print(log[1])
但我得到這個錯誤:
b'pg_dump: too many command-line arguments (first is ">")\nTry "pg_dump --help" for more information.\n'
有什么想法嗎?
uj5u.com熱心網友回復:
您可能需要將 shell 命令設為可執行檔案,然后將整個命令傳遞給該 shell,如下所示:
command = "sh -c 'pg_dump --dbname .....'"
看到這個問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444058.html
標籤:Python PostgreSQL 码头工人
