database - 在 Amazon VM 上上传 Postgres 数据库

标签 database postgresql upload amazon-ec2 virtual-machine

由于可用存储空间和内存很少,我无法使用我的电脑处理一个数据库。

给我这个数据库的人给了我以下详细信息:

The compressed file is about 15GB, and uncompressed it's around 85-90GB. It'll take a similar amount of space once restored, so make sure the machine that you restore it on has at least 220GB free to be safe. Ideally, use a machine with at least 8GB RAM - although even our modest 16GB RAM server can struggle with large queries on the tweet table.

You'll need PostgreSQL 8.4 or later, and you'll need to create a database to restore into with UTF8 encoding (use -E UTF8 when creating it from the command-line). If this is a fresh PostgreSQL install, I highly recommend you tweak the default postgresql.conf settings - use the pgtune utility (search GitHub) to get some sane defaults for your hardware. The defaults are extremely conservative, and you'll see terrible query performance if you don't change them.

当我告诉他我的电脑有点糟糕时,他建议我使用 Amazon EC2 实例

我的两个问题是:

  1. 如何将数据库上传到 Amazon VM?
  2. 之后我该如何使用它?

如您所见,我对云服务和数据库完全无知。任何相关教程将不胜感激。

最佳答案

如果您是云托管新手,请考虑使用 EnterpriseDB's cloud options,而不是直接使用 EC2 。 Details here .

如果您想直接使用 EC2,请注册并创建实例。

选择您喜欢的 Linux 发行版镜像。我假设您将在 EC2 上使用 Linux;如果您想使用 Windows,那是因为您可能已经知道如何使用。让新的虚拟机配置并启动,然后根据 Amazon EC2 和该特定虚拟机镜像上提供的文档通过 SSH 连接到该虚拟机。按照该虚拟机镜像的文档执行任何建议的设置。

完成该实例的建议设置后,您可以安装 PostgreSQL:

  • 对于 Ubuntu,apt-get install postgresql
  • 对于 Fedora,yum install postgresql
  • 对于 CentOS,请使用 PGDG yum repository不是提供的 PostgreSQL 过时版本。

您现在可以作为默认 postgres super 用户连接到 Pg:

sudo -u postgres psql

并且能够像在任何其他计算机上一样使用 PostgreSQL。您可能需要为自己创建一个用户 ID 和一个要恢复到的新数据库:

echo "CREATE USER $USER;" | sudo -u postgres psql
echo "CREATE DATABASE thedatabase WITH OWNER $USER" | sudo -u postgres psql

当然,将“thedatabase”更改为您想要调用的数据库。

将转储恢复到新数据库的确切过程取决于转储格式。

对于 pg_dump -Fc 或 PgAdmin-III 自定义格式转储:

sudo -u postgres pg_restore --dbname thedatabase thebackupfile

请参阅“man pg_restore”和online documentation有关 pg_restore 的详细信息。

对于纯 SQL 格式转储,您需要通过解压缩程序将转储流式传输到 psql。由于您没有提及转储文件名或格式,因此很难知道该怎么做。我假设它是 gzip'ed(“.gz”文件扩展名),在这种情况下你会这样做:

gzip -d thedumpfile.gz | sudo -u postgres psql thedatabase

如果文件扩展名是“.bz2”,请将 gzip 更改为 bzip2。如果它是 .zip,您需要将其解压缩,然后使用 sudo -u postgres psql -f thedumpfilename 运行 psql .

恢复后,您可以使用psql thedatabase连接到数据库。

关于database - 在 Amazon VM 上上传 Postgres 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11940594/

相关文章:

SQL从三个表中选择至少两个不同的值连接在一起

sql - 除非存在变量,否则使用 NOT LIKE 排除

.net - 使用 .Net 应用程序部署 MySQL Server + DB

ruby-on-rails - 使用特定于数据库的数据类型进行 Rails 迁移

c# - 如何检查文档是否为有效的 PDF 文档

python - 使用python将文件上传到SFTP

android - 在 Node.js Hapi 上大文件上传失败

database - 文本内容需要推荐,我应该使用文本文件还是数据库?

database - 函数依赖的规范覆盖

python将独特的项目添加到一个巨大的表中