MOCKSTACKS
EN
Questions And Answers

More Tutorials









postgreSQL install via MacPorts on OSX


In order to install PostgreSQL on OSX, you need to know which versions are currently supported.

Use this command to see what versions you have available.

sudo port list | grep "^postgresql[[:digit:]]\{2\}[[:space:]]"

You should get a list that looks something like the following:

postgresql80 @8.0.26 databases/postgresql80
postgresql81 @8.1.23 databases/postgresql81
postgresql82 @8.2.23 databases/postgresql82
postgresql83 @8.3.23 databases/postgresql83
postgresql84 @8.4.22 databases/postgresql84
postgresql90 @9.0.23 databases/postgresql90
postgresql91 @9.1.22 databases/postgresql91
postgresql92 @9.2.17 databases/postgresql92
postgresql93 @9.3.13 databases/postgresql93
postgresql94 @9.4.8 databases/postgresql94
postgresql95 @9.5.3 databases/postgresql95
postgresql96 @9.6beta2 databases/postgresql96

In this example, the most recent version of PostgreSQL that is supported in 9.6, so we will install that.

sudo port install postgresql96-server postgresql96

You will see an installation log like this:

---> Computing dependencies for postgresql96-server
---> Dependencies to be installed: postgresql96
---> Fetching archive for postgresql96
---> Attempting to fetch postgresql96-9.6beta2_0.darwin_15.x86_64.tbz2 from
https://packages.macports.org/postgresql96
---> Attempting to fetch postgresql96-9.6beta2_0.darwin_15.x86_64.tbz2.rmd160 from
https://packages.macports.org/postgresql96
---> Installing postgresql96 @9.6beta2_0
---> Activating postgresql96 @9.6beta2_0
To use the postgresql server, install the postgresql96-server port
---> Cleaning postgresql96
---> Fetching archive for postgresql96-server
---> Attempting to fetch postgresql96-server-9.6beta2_0.darwin_15.x86_64.tbz2 from
https://packages.macports.org/postgresql96-server
---> Attempting to fetch postgresql96-server-9.6beta2_0.darwin_15.x86_64.tbz2.rmd160 from
https://packages.macports.org/postgresql96-server
---> Installing postgresql96-server @9.6beta2_0
---> Activating postgresql96-server @9.6beta2_0
To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql96/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql96/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql96/bin/initdb -D
/opt/local/var/db/postgresql96/defaultdb'
---> Cleaning postgresql96-server
---> Computing dependencies for postgresql96
---> Cleaning postgresql96
---> Updating database of binaries
---> Scanning binaries for linking errors
---> No broken files found.

The log provides instructions on the rest of the steps for installation, so we do that next.

sudo mkdir -p /opt/local/var/db/postgresql96/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql96/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql96/bin/initdb -D
/opt/local/var/db/postgresql96/defaultdb'

Now we start the server:

sudo port load -w postgresql96-server

Verify that we can connect to the server:

su postgres -c psql

You will see a prompt from postgres:

psql (9.6.1)
Type "help" for help.
postgres=#

Here you can type a query to see that the server is running.

postgres=#SELECT setting FROM pg_settings WHERE name='data_directory';

And see the response:

 setting
------------------------------------------
/opt/local/var/db/postgresql96/defaultdb
(1 row)
postgres=#

Type \q to quit:

postgres=#\q

And you will be back at your shell prompt.

Congratulations! You now have a running PostgreSQL instance on OS/X.

Conclusion

In this page (written and validated by ) you learned about postgreSQL install via MacPorts on OSX . What's Next? If you are interested in completing postgreSQL tutorial, your next topic will be learning about: postgreSQL Accessing Data Programmatically.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.