Skip to content

Instantly share code, notes, and snippets.

@AD0791
Last active February 10, 2020 22:47
Show Gist options
  • Save AD0791/cc60f07acf5a655fa7b751523712a365 to your computer and use it in GitHub Desktop.
Save AD0791/cc60f07acf5a655fa7b751523712a365 to your computer and use it in GitHub Desktop.
Postgresql
Remove previous versions of PostgreSQL
brew uninstall --force postgresql
Delete all Files of Postgres
rm -rf /usr/local/var/postgres
Install Postgres with Homebrew
brew install postgres
Install PostGIS with Homebrew
brew install postgis
Start PostgreSQL server
pg_ctl -D /usr/local/var/postgres start
Create Database
initdb /usr/local/var/postgres
If terminal shows an error
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
Remove old database file
rm -r /usr/local/var/postgres
Run the initdb command again
initdb /usr/local/var/postgres
Create a new database
createdb postgis_test
Enable PostGIS
psql postgis_test
This command should show the psql command prompt
psql (10.0)
type “help” for help
postgis_test=#
Creating extension for PostGIS.
CREATE EXTENSION postgis;
If everything goes well we should see:
postgis_test=#CREATE EXTENSION postgis;
CREATE EXTENSION
postgis_test=#
Check your PostGIS version
SELECT PostGIS_Version();
Hopefully this article will save your time .
------ after install message from brew-----
==> postgresql
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
To have launchd start postgresql now and restart at login:
brew services start postgresql
TO STOP THE SERVER
brew services stop postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
To stop the server:
pg_ctl -D /usr/local/var/postgres stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment