I'm trying to create a PostgreSQL local db dump via Terminal on macOS using psql. My next step is to upload/import my entire db to my Amazon RDS PostgreSQL db instance.
Can anyone help me with the Terminal command to create a dump file 'mydbdump.sql' for my 'mydb' database. I've sorted through existing questions, searched forums (tried similar Stack Overflow question), even Amazon RDS docs (above, link), and am having no luck with the commands from any of these docs. What am I doing wrong?
Here is what I've tried so far (and I've gotten nothing back, not even an error):
Via sudo:
sudo -u postgres psql pg_dump -Fc -o -f /Users/<my_computer>/database_backup.sql mydb
Via psql, connected to mydb (\c mydb;
):
mydb-# pg_dump dbname=mydb -f mydbdump.sql
mydb-# pg_dump -U postgres -W -F t mydb > /Users/<my_computer>/database_backup.sql
mydb-# pg_dump -Fc mydb > /Users/<my_computer>/database_backup.sql
mydb-# pg_dump -U postgres mydb > database_backup.sql
mydb-# pg_dump -Fc mydb > /Users/<my_computer>/database_backup.sql
mydb-# pg_dump -U postgres -W -F t mydb > /Users/<my_computer>/database_backup.sql
For reference: I'm using Django, in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'dbuser',
'PASSWORD': '<MYPASSWORD>',
'HOST': 'localhost',
'PORT': '',
}
}
By the way, my Django app is running successfully.
When I list all database relations in mydb:
\dt mydb;
Output:
List of relations
Schema | Name | Type | Owner
--------+----------------------------+-------+--------
public | auth_group | table | dbuser
public | auth_group_permissions | table | dbuser
public | auth_permission | table | dbuser
public | auth_user | table | dbuser
public | auth_user_groups | table | dbuser
public | auth_user_user_permissions | table | dbuser
public | django_admin_log | table | dbuser
public | django_content_type | table | dbuser
public | django_migrations | table | dbuser
public | django_session | table | dbuser
public | polls_choice | table | dbuser
public | polls_question | table | dbuser
(12 rows)
When I list all schemas in psql:
select s.nspname as table_schema,
s.oid as schema_id,
u.usename as owner
from pg_catalog.pg_namespace s
join pg_catalog.pg_user u on u.usesysid = s.nspowner
order by table_schema;
Output:
table_schema | schema_id | owner
--------------------+-----------+----------
information_schema | 13337 | postgres
pg_catalog | 11 | postgres
pg_temp_1 | 12314 | postgres
pg_toast | 99 | postgres
pg_toast_temp_1 | 12315 | postgres
public | 2200 | postgres