Migrate postgres dump to RDS

依然范特西╮ 提交于 2021-02-07 08:09:21

问题


I have a Django postgres db (v9.3.10) running on digital ocean and am trying to migrate it over to Amazon RDS (postgres v 9.4.5). The RDS is a db.m3.xlarge instance with 300GB. I've dumped the Digital Ocean db with:

sudo -u postgres pg_dump -Fc -o -f /home/<user>/db.sql <dbname>

And now I'm trying to migrate it over with:

 pg_restore -h <RDS endpoint> --clean -Fc -v -d <dbname> -U <RDS master user> /home/<user>/db.sql

The only error I see is:

  pg_restore: [archiver (db)] Error from TOC entry 2516; 0 0 COMMENT EXTENSION plpgsql
  pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of extension plpgsql
  Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

Apart from that everything seems to be going fine and then it just grinds to a halt. The dumped file is ~550MB and there are a few tables with multiple indices, otherwise pretty standard.

The Read and Write IOPS on the AWS interface are near 0, as is the CPU, memory, and storage. I'm very new to AWS and know that the parameter groups might need tweaking to do this better. Can anyone advise on this or a better way to migrate a Django db over to RDS?

Edit:

Looking at the db users the DO db looks like:

Role Name   Attr                                           Member Of
<user>      Superuser                                      {}
postgres    Superuser, Create role, Create DB, Replication {}

And the RDS one looks like:

Role Name      Attr                     Member Of
<user>        Create role, Create DB    {rds_superuser}
rds_superuser Cannot login              {}
rdsadmin      ...                        ...

So it doesn't look like it's a permissions issue to me as <user> has superuser permissions in each case.

Solution for anyone looking:

I finally got this working using:

cat <db.sql> | sed -e '/^COMMENT ON EXTENSION plpgsql IS/d' > edited.dump
psql -h <RDS endpoint> -U <user> -e <dname> < edited.dump

It's not ideal for a reliable backup/restore mechanism but given it is only a comment I guess I can do without. My only other observation is that running psql/pg_restore to a remote host is slow. Hopefully the new database migration service will add something.


回答1:


Considering your dumped DB file is of ~550MB, I think using the Amazon guide for doing this is the way out. I hope it helps.

Importing Data into PostgreSQL on Amazon RDS




回答2:


I think it did not halt. It was just recreating indexes, foreign keys etc. Use pg_restore -v to see what's going on during the restore. Check the logs or redirect output to a file to check for any errors after import, as this is verbose.

Also I'd recommend using directory format (pg_dump -v -Fd) as it allows for parallel restore (pg_restore -v -j4).

You can ignore this ERROR: must be owner of extension plpgsql. This is only setting a comment on extension, which is installed by default anyway. This is caused by a peculiarity in RDS flavor of PostgreSQL, which does not allow to restore a database while connecting as postgres user.



来源:https://stackoverflow.com/questions/36311692/migrate-postgres-dump-to-rds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!