PostgreSQL Installation on Mac: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=


* [[Postgresql#Subjects|Postgresql]]
* [[PostgreSQL#Subjects|PostgreSQL]]
* [[PostgreSQL Operations]]


=Overview=
=Overview=


brew install postgresql
==Initial Installation==
<syntaxhighlight lang='bash'>
brew install postgresql
</syntaxhighlight>
===Configure Environment===
The installation output will contain the value to used for <code>-D</code> flag (the database directory).


=Start at Login=
Write it down and set the <code>PGDATA</code> environment variable to that value, so <code>pg_ct</code> commands will work without an explicit <code>-D</code>.


To have launchd start postgresql now and restart at login:
Add to <code>.bashrc</code>:
<syntaxhighlight lang='bash'>
export PGDATA=/opt/brew/var/postgresql@14
</syntaxhighlight>
See: {{Internal|PostgreSQL_Concepts#PGDATA|PGDATA}}


  brew services start postgresql
==Update Already Installed Package==
 
brew upgrade postgresql
=Operate the Database as a Service=
 
==Start at Login==
 
To have <code>[[Mac launchd|launchd]]</code> start <code>postgresql</code> now and restart at login:
<syntaxhighlight lang='bash'>
brew services start postgresql@14
</syntaxhighlight>
 
For more details, see: {{Internal|Brew_Operations#services|<tt>brew services</tt>}}


=To Run without a Service=
=To Run without a Service=
<syntaxhighlight lang='bash'>
/opt/brew/opt/postgresql@14/bin/postgres -D /opt/brew/var/postgresql@14
</syntaxhighlight>
<font color=darkkhaki>Explore equivalency with:
<syntaxhighlight lang='bash'>
pg_ctl -D /usr/local/var/postgres start
</syntaxhighlight>
==Status==
  pg_ctl -D /usr/local/var/postgres status
==Stop==


   pg_ctl -D /usr/local/var/postgres start
   pg_ctl -D /usr/local/var/postgres stop

Latest revision as of 21:38, 6 October 2023

Internal

Overview

Initial Installation

brew install postgresql

Configure Environment

The installation output will contain the value to used for -D flag (the database directory).

Write it down and set the PGDATA environment variable to that value, so pg_ct commands will work without an explicit -D.

Add to .bashrc:

export PGDATA=/opt/brew/var/postgresql@14

See:

PGDATA

Update Already Installed Package

brew upgrade postgresql

Operate the Database as a Service

Start at Login

To have launchd start postgresql now and restart at login:

brew services start postgresql@14

For more details, see:

brew services

To Run without a Service

/opt/brew/opt/postgresql@14/bin/postgres -D /opt/brew/var/postgresql@14

Explore equivalency with:

pg_ctl -D /usr/local/var/postgres start

Status

  pg_ctl -D /usr/local/var/postgres status

Stop

  pg_ctl -D /usr/local/var/postgres stop