Difference between revisions of "Postgresql"

From John Freier
Jump to: navigation, search
(Issues)
Line 18: Line 18:
  
 
FYI, haven't tried but look like a nicer app to control Postgres is https://postgresapp.com.
 
FYI, haven't tried but look like a nicer app to control Postgres is https://postgresapp.com.
 +
 +
== Environment Path ==
 +
To add PostgreSQL in to your environment path.
 +
 +
  export POSTGRESQL_HOME=/Library/PostgreSQL/11
 +
  PATH=$PATH:$POSTGRESQL_HOME/bin
 +
 +
 +
== Run file and commands from CLI ==
 +
PSQL will ask for your password every time unless you set it as an environment variable.
 +
  export PGPASSWORD=Password123
 +
 +
To run a command.
 +
  psql -U user_name -d database_name -c "SELECT * FROM tblExample"
 +
 +
To run a file.
 +
  psql -U user_name -d database_name -f ./file.sql
  
 
== Issues ==
 
== Issues ==

Revision as of 13:13, 17 December 2020

Test Database Connection

This is a way to test the database connection.

 ./pg_isready -h localhost -p 5432

Application Structure

Log location

./data/log/

OSX

The Postgres app live here on OSX

 /Library/PostgreSQL/11

Start

 sudo -u postgres ./bin/pg_ctl -D ./data start

Stop

 sudo -u postgres ./bin/pg_ctl -D ./data stop

FYI, haven't tried but look like a nicer app to control Postgres is https://postgresapp.com.

Environment Path

To add PostgreSQL in to your environment path.

 export POSTGRESQL_HOME=/Library/PostgreSQL/11
 PATH=$PATH:$POSTGRESQL_HOME/bin


Run file and commands from CLI

PSQL will ask for your password every time unless you set it as an environment variable.

 export PGPASSWORD=Password123

To run a command.

 psql -U user_name -d database_name -c "SELECT * FROM tblExample"

To run a file.

 psql -U user_name -d database_name -f ./file.sql

Issues

Error Connecting to database FATAL : no pg_hba.conf entry for host I had to add the host ip address into the pg_hba.conf file.

location of file: ./data/pg_hba.conf

Added the following line and then restarted Postgres.

 host    all             all             10.225.41.95/24        md5