Connecting to PSQL¶
Connection string¶
postgres://YourUserName:YourPassword@YourHostname:5432/YourDatabaseName
pg_dump¶
-Fccustom format (aka zipped)-ffile name-Texcludes a table, there can be multiple-tonly include this table, there can be multiple
pg_restore¶
-dalso accepts a local db name--no-ownerremoves the ownership--no-aclremoves access privileges (grant/revoke commands)--section=pre-data,data,post-data- pre-data: table/schema def, sequences, owner,
- post-data: (foreign) constraints
Copy a table in the same db¶
Copy table to another database¶
- dumps as a
.sqlfile so you can just run withpsql
Cloud access¶
AWS RDS on a VPC via SSM¶
- Create an ssh tunnel from your machine to an EC2 container in the VPC
aws ssm start-session --target "container-id-ec2, like i-0373fb85e5fbc7d8e" --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["22"],"localPortNumber":["56789"]}'
-
Connect to the
ssh -p 56789 root@localhost
-
note the user should be
rootor whatever is expected on the EC2 machine -
not your personal username
-
ssh root@127.0.0.1 -p 56789 -N -L 5433:{prod db url}:5432
Last update:
2023-04-24