【问题标题】:How to remote access PostgreSQL database and get its dump to local?如何远程访问 PostgreSQL 数据库并将其转储到本地?
【发布时间】:2016-11-28 06:33:23
【问题描述】:

我需要访问远程数据库服务器 (linux) 并将其转储到我的本地 (mac)。

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'test-name',
    'USER': 'test-user',
    'PASSWORD': 'pwd',
    'HOST': 'test.amazonaws.com',
    }
}

【问题讨论】:

标签: python django database postgresql


【解决方案1】:

在本地 bash 中,您可以使用pg_dump 命令连接和转储远程数据库,请参阅Copying PostgreSQL database to another server

使用 Python 类似,只是需要使用psycopg2 模块连接并发送命令到数据库服务器。你可能会发现这篇文章很有用Postgresql Database Backup Using Python

或者,如果您需要在数据库服务器中执行脚本,更好的办法是远程转储它,然后将其提取到本地机器。

【讨论】:

    猜你喜欢
    • 2019-12-27
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    相关资源
    最近更新 更多