Difference between revisions of "Postgres"

From Steak Wiki
Jump to navigationJump to search
(Created page with " ==Create a user== * https://wiki.debian.org/PostgreSql Note that if you have an existing db, you might want to add ownership to this user, or r/w permissions.")
 
Line 1: Line 1:
  
  
 
+
==Backup / Restore DB==
 +
This will run the dump as the postgres user via su, and avoids some of the permissions errors that can creep up.
 +
# cd /tmp
 +
(just need a writeable directory, aka 777)
 +
# su -c 'pg_dump mydb >> mydb_dump_2020.sql' postgres
 +
assuming you have a postgres admin user, with all rights, this will backup the db. If you are remote, you might need something similar to (localhost/ip, ports, etc specified):
 +
pg_dump -U username -h localhost databasename >> sqlfile.sql
  
 
==Create a user==
 
==Create a user==

Revision as of 04:09, 28 June 2020


Backup / Restore DB

This will run the dump as the postgres user via su, and avoids some of the permissions errors that can creep up.

# cd /tmp
(just need a writeable directory, aka 777)
# su -c 'pg_dump mydb >> mydb_dump_2020.sql' postgres

assuming you have a postgres admin user, with all rights, this will backup the db. If you are remote, you might need something similar to (localhost/ip, ports, etc specified):

pg_dump -U username -h localhost databasename >> sqlfile.sql

Create a user

Note that if you have an existing db, you might want to add ownership to this user, or r/w permissions.