Installing Postgres Tweet For Mac. For Linux For APT systems (Ubuntu, Debian, Mint, Etc) sudo apt-get install postgresql For Arch Linux. GUI Client Apps. There are many clients for PostgreSQL on the Mac. You can find many of them in the Community Guide to PostgreSQL GUI Tools in the PostgreSQL wiki. Some of them are quite powerful; some are still a bit rough. Uninstall the old PostgreSQL server first, then start Postgres.app again. It can also happen when a different user on your Mac is already running Postgres.app. Only a single server can run on each port. If you want to use multiple PostgreSQL servers simultaneously, configure them to use a different port.
Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac app.It includes everything you need to get started:we’ve even included popular extensions like PostGIS for geo data and plv8 for JavaScript.
Postgres.app has a beautiful user interface and a convenient menu bar item.You never need to touch the command line to use it – but of course we do include all the necessary command line tools and header files for advanced users.
Postgres.app can install minor updates automatically, so you get bugfixes as soon as possible.
Installing Postgres.app
- Download ➜ Move to Applications folder ➜ Double ClickIf you don't move Postgres.app to the Applications folder, you will see a warning about an unidentified developer and won't be able to open it.
- Click 'Initialize' to create a new server
- Configure your $PATH to use the included command line tools (optional):
Done! You now have a PostgreSQL server running on your Mac with these default settings:
Host | localhost |
Port | 5432 |
User | your system user name |
Database | same as user |
Password | none |
Connection URL | postgresql://localhost |
To connect with psql, double click a database. To connect directly from the command line, type
psql
. If you’d rather use a graphical client, see below.NOTE: These instructions assume that you’ve never installed PostgreSQL on your Mac before.If you have previously installed PostgreSQL using homebrew, MacPorts, the EnterpriseDB installer, consider removing other PostgreSQL installations first.We also have instructions for upgrading from older versions of Postgres.app.
Graphical Clients
Postgres.app includes
psql
, a versatile command line client for PostgreSQL.But it’s not the only option; there are plenty of great graphical clients available for PostgreSQL.Two popular tools are:pgAdmin 4 is a feature rich open source PostgreSQL client.It has support for almost every feature in PostgreSQL.The only downside is that the cross-plattform UI really doesn’t live up to the expectations of a native Mac app.
Postico on the other hand, is a very modern Mac app.It’s made by the same people that maintain Postgres.app, and we think you’ll like it! We put a lot of effort into making it a joy to use.However, it doesn’t have the extensive feature set of pgAdmin, and it’s a commercial app rather than open source.
Aside from those two options, there are a lot more to choose from! Check the documentation for a list of amazing Mac apps for PostgreSQL.
How to connect
After your PostgreSQL server is up and running, you’ll probably want to connect to it from your application.Here’s how to connect to PostgreSQL from popular programming languages and frameworks:
To connect from PHP, make sure that it supports PostgreSQL. The version included with macOS doesn't support PostgreSQL. We recommend MAMP for an easy way to install a current version of PHP that works.
You can use PDO (object oriented):
Or the pg_connect() functions (procedural):
To connect to a PostgreSQL server with Python, please first install the psycopg2 library:
Django
In your settings.py, add an entry to your DATABASES setting:
Flask
When using the Flask-SQLAlchemy extension you can add to your application code:
SQLAlchemy
To install the pg gem, make sure you have set up your $PATH correctly (see Command-Line Tools), then execute the following command:
Rails
In config/database.yml, use the following settings:
Sinatra
In config.ru or your application code:
ActiveRecord
Install the activerecord gem and require 'active_record', and establish a database connection:
DataMapper
Mac interior design apps. Install and require the datamapper and do_postgres gems, and create a database connection:
Sequel
Install and require the sequel gem, and create a database connection:
- Download and install the PostgreSQL JDBC driver
- Connect to the JDBC URL jdbc:postgresql://localhost
For more information see the official PostgreSQL JDBC documentation.
libpq is the native C client library for connecting to PostgreSQL. It's really easy to use:
Now compile the file with clang and run it:
You can just use the C API in Swift! First include libpq in your bridging header:
Then make sure to link with libpq.
On iOS, you'll need to build libpq yourself.
On macOS you can use the system provided libpq (does not support SSL) or use libpq provided by Postgres.app by adding the following build settings:
Other Linker Flags | -lpq |
---|---|
Header Search Paths | /Applications/Postgres.app/Contents/Versions/latest/include |
Library Search Paths | /Applications/Postgres.app/Contents/Versions/latest/lib |
Now you can use the libpq C library to connect to PostgreSQL:
Support
We have a list of common problems in the troubleshooting section in the documentation.
For general questions concerning PostgreSQL, have a look at the official PostgreSQL documentation.
If you have a question concerning Postgres.app that is not answered by the Postgres.app documentation,you can ask @PostgresApp on Twitter, or open an issue on GitHub.
When reporting bugs, let us know which version of Postgres.app & macOS you are using, and be sure to include detailed error messages, even if your issue seems similar to another one.
License
Postgres.app, PostgreSQL, and its extensions are released under the PostgreSQL License. The released binaries also include OpenSSL (OpenSSL License), PostGIS (GPLv2), and plv8 (3 clause BSD).
Postgres.app is maintained by Jakob Egger. It was originally created by Mattt Thompson.
Troubleshooting & Support
Common errors
The following list contains all errors which may occur while you’re using Postgres.app.
The binaries for this PostgreSQL server were not found
Postgres.app includes the PostgreSQL binaries inside the application package.By default, PostgreSQL version 9.5 and 9.6 are included.
This error means that the binaries for this server were not found. This could happen if a future version of Postgres.app drops does not include your version of PostgreSQL anymore.It could also happen if you manually added older binaries to Postgres.app, and then you updated Postgres.app.
To fix this issue, make sure that the correct binaries for your server are in
/Applications/Postgres.app/Contents/Versions/
Port [number] is already in use
This error usually means that you already have a PostgreSQL server running on your Mac. Uninstall the old PostgreSQL server first, then start Postgres.app again.
It can also happen when a different user on your Mac is already running Postgres.app.Only a single server can run on each port.
How to set app authentication on mac. If you want to use multiple PostgreSQL servers simultaneously, configure them to use a different port.
There is already a PostgreSQL server running in this data directory
Postgresql Mac Os
This can happen if you’ve configured Postgres.app to use a data directory that is used by a different PostgreSQL installation.Stop the other server before starting Postgres.app.In general, it is not recommended to just use a data directory created by another version of PostgreSQL, since it might have been configured differently.
The data directory contains an old postmaster.pid file / The data directory contains an unreadable postmaster.pid file
PostgreSQL puts a file named
postmaster.pid
in the data directory to store the process id of the PostgreSQL server process.If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL.You can fix this issue by deleting the postmaster.pid
file. However, you must make sure that PostgreSQL is really not running.Open Activity Monitor and make sure that there are no processes named ‘postgres’ or ‘postmaster’.If you delete the
postmaster.pid
file while PostgreSQL is running, bad things will happen.Could not initialize database cluster
![Postgresql on mac Postgresql on mac](/uploads/1/3/4/2/134261501/154903574.png)
This error means that the
initdb
command failed.This should not happen. If it does, please open an issue on Github.For troubleshooting, try executing the following command manually:Could not create default user / Could not create user database
After the data directory is initialized, Postgres.app creates a default user and database.This error means that creating the user has failed. Check the server log (inside the data directory) for details.
You can try creating a default user and database manually:
Postgres.app uses your system user name for USERNAME and DATABASENAME by default.
Postgresql Mac Download
File [or Folder] not found. It will be created the first time you start the server
Data directories and all its contents are only created when you start a server the first time.This error occurs when you attempt to open a data directory (or file) which doesn’t exist yet.Start the server first and try again.
Unknown Error
This error should not occur.Please open an issue on Github and provide a detailed description what lead to this error.
Errors in the server log
The server log is inside the data directory in a file named
postgres-server.log
.Here are some errors that could appear:
Could not create listen socket for “localhost”
Usually this error is caused by broken
/etc/hosts
file.The problem could be a missing localhost
entry, syntax errors or incorrect whitespace.For reference, here is what this file should look like by default on macOS:
database files are incompatible with server: The database cluster was initialized with PG_CONTROL_VERSION x, but the server was compiled with PG_CONTROL_VERSION y
This error usually happens when you try to start a server that was initialized with a prerelease version of PostgreSQL.The on disk data format sometimes changes between pre-release versions.You need to start the server with the version you initialized it with, then dump the database, then create a new server with the new version and restore.
Errors when connecting to the PostgreSQL server
psql: FATAL: role “USERNAME” does not exist
By default, Postgres.app creates a PostgreSQL user with the same user as your system user name.When this error occurs, it means that this user does not exist.You can create it by executing the following command in the Terminal:
- Make sure your $PATH is configured correctly
- Execute the command
createuser -U postgres -s $USER
-U postgres
tells createuser to connect with thepostgres
user name-s
tells createuser to create a super user$USER
is a variable containing your system user name, and tells createuser the name of the postgres user you want to create
psql: FATAL: database “USERNAME” does not exist
By default, psql tries to connect to a database with the same name as your local user.This error means that this database does not exist. This can have several possible reasons:
- Postgres.app failed to create the default database when initializing the server
- You deleted the default database
- Your user name is different from the user name that initialized the server
There are multiple ways to fix this problem:
- Make sure your $PATH is configured correctly
- You can create the missing database using the command
createdb $USER
, or - You can connect to a different database, eg.
psql postgres
to connect to the other default database
Could not translate host name “localhost”, service “5432” to address: nodename nor servname provided, or not known
Usually this error is caused by broken
/etc/hosts
file.The problem could be a missing localhost
entry, syntax errors or incorrect whitespace.For reference, here is what this file should look like by default on macOS:
psql: FATAL: could not open relation mapping file “global/pg_filenode.map”: No such file or directory
This error can occur when you delete the data directory while the PostgreSQL server is still running.To fix it, kill all PostgreSQL processes or restart your computer.Then start a new PostgreSQL server.
Starting the server manually
For debugging, it is often useful to try starting the server manually:
- Quit Postgres.app
- Open the Terminal and type
/Applications/Postgres.app/Contents/Versions/latest/bin/postgres -D 'DATA DIRECTORY' -p PORT
(replace DATA DIRECTORY with your data directory, make sure to include the quotes because the path might contain spaces) - Now you should see a more detailed error message why the server failed to start
Resetting Postgres.app
If you somehow mess up your Postgres.app installation, here’s how to start fresh.
CAUTION: This will delete all your databases, tables and data!
CAUTION: This will delete all your databases, tables and data!
- Quit Postgres.app
- Open Activity Monitor, see if any processes name
postgres
are running. If so, kill them. Kill the process with the lowest pid first; child processes are respawned automatically after killing them. - Delete the Folder
~/Library/Application Support/Postgres
- Delete all settings using the command:
defaults delete com.postgresapp.Postgres2
- Open Postgres.app again
Technical Support
If you run into any issues using Postgres.app, your first stop should be the issue tracker on Github.You can also ask @PostgresApp on Twitter.
Help others
If you encounter an issue and find a way to fix it, consider contributing to this documentation. This page is hosted on Github.