Showing posts with label postgreSQL. Show all posts
Showing posts with label postgreSQL. Show all posts

Friday, May 6, 2016

PostgreSQL database backup and restore

I needed to backup a DB then reset a VM and then put the backup on it.
This is what I did ( I think )

To dump it to a file of sql commands:

pg_dump -U [user-name] [source db name] -f [name of file to dump it to]

One nice thing is that it is human readable.

To reinstall it:

  1. I had to drop the existing DB with the same name ( I used pgAdmin III to do so)
  2. I recreated an empty DB with the same name, and since I needed extensions, I added the 2 extensions I needed.
  3. Then I loaded it in ( which could have been to a different DB name, but in my case I used the same one ):
pgsl -U [user-name] -d [db name to restore to] -f [name of the dump file]

Also note that the commands are found in PostgreSQL's bin directory.

Thursday, April 7, 2016

Postgres getting the description of a table, specifically column names

Do this:

SELECT column_name, data_type FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'table_name_goes_here';

Friday, January 29, 2016

Postgres - Seeing what connections exist and where they are to and from

Found this Postgres command to show all the connections, their sources, what dbs they are connected to.

SELECT * FROM pg_stat_activity


Tuesday, August 18, 2015

PostgreSQL Allow Connections from Everywhere

PostgreSQL doesn't normally allow connections from everywhere.
But for development you might want to enable it.

On Windows, a typical path to the file to edit is like:
C:\Program Files\PostgreSQL\9.4\data\pg_hba.conf

Add a line like this to the end of that file:
host    all             all             0.0.0.0/0            md5

Also make sure your firewall allows remote machines to get in, or it won't matter if _only_ postgres allows them.