Friday, August 23, 2019

Install PostgreSQL 10.2

Install PostgreSQL 10.2


Introduction

Even I know much better of MySQL than PostgreSQL, I still prefer PostgreSQL. PostgreSQL is easier to be compiled and less dependency issue. I have successfully compile PostgreSQL on older system, as old as Mac OS X 10.6 Snow Leopard.

Compile and install

The easiest for me is use homebrew. PostgreSQL 10 data format is not compatible with version 9, so backup before you install PostgreSQL 10. The data may be in /usr/local/var/postgres

$ brew install postgres
...
$ cat /usr/local/var/postgres/PG_VERSION
9.4

If installed before backup or upgrade the old database, try
$ brew postgresql-upgrade-database

Setup and startup

To start PostgreSQL
$ pg_ctl -D /usr/local/var/postgres [-l /tmp/postgresql10.log] start
$ pg_ctl -D /usr/local/var/postgres stop

Note: I will prefer to use /usr/local/data/postgres directory.

You can use environment PGDATA=/usr/local/var/postgres
$ pg_ctl -l /tmp/postgresql10.log start

If there is no database in PGDATA directory
$ initdb -D /usr/local/var/postgres
$ cat /usr/local/var/postgres/PG_VERSION
10

Using postgresql

$ psql [ <database> ] [-U <user>]
$ psql postgresql
psql (10.2, server 10.1)
Type "help" for help.

postgres=#\q (quit)

Note: Seems like my database is created by PostgreSQL 10.1? To check version => select version();

Default database is postgres. You should create another user and database for development or testing purpose. The progress is not covered here.

No comments: