Skip to content

Instantly share code, notes, and snippets.

@mikesjewett
Created September 22, 2012 04:20
Show Gist options
  • Save mikesjewett/3765102 to your computer and use it in GitHub Desktop.
Save mikesjewett/3765102 to your computer and use it in GitHub Desktop.
PG reinstall from scratch
new-host-2:ltp mike$ brew remove postgresql
Uninstalling /usr/local/Cellar/postgresql/9.1.4...
new-host-2:ltp mike$ brew install postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.bz2
Already downloaded: /Library/Caches/Homebrew/postgresql-9.1.4.tar.bz2
==> Patching
patching file src/pl/plpython/Makefile
patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.4 --datadir=/usr/local/Cellar/postgresql
==> make install-world
==> Caveats
# Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
To build plpython against a specific Python, set PYTHON prior to brewing:
PYTHON=/usr/local/bin/python brew install postgresql
See:
http://www.postgresql.org/docs/9.1/static/install-procedure.html
# Create/Upgrade a Database
If this is your first install, create a database with:
initdb /usr/local/var/postgres
To migrate existing data from a previous major version (pre-9.1) of PostgreSQL, see:
http://www.postgresql.org/docs/9.1/static/upgrading.html
# Start/Stop PostgreSQL
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
If this is an upgrade and you already have the homebrew.mxcl.postgresql.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or start manually with:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
And stop with:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
# Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a list of all
available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database and run:
CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database, run:
CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.1/static/sql-createextension.html
For more information on extensions, see:
http://www.postgresql.org/docs/9.1/static/contrib.html
# Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
To install postgresql (and ossp-uuid) in 32-bit mode:
brew install postgresql --32-bit
If you want to install the postgres gem, including ARCHFLAGS is recommended:
env ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
==> Summary
/usr/local/Cellar/postgresql/9.1.4: 2751 files, 36M, built in 110 seconds
new-host-2:ltp mike$ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "mike".
This user must also own the server process.
The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".
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".
new-host-2:ltp mike$ rm /usr/local/var/postgres
rm: /usr/local/var/postgres: is a directory
new-host-2:ltp mike$ rm -r /usr/local/var/postgres
new-host-2:ltp mike$ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "mike".
This user must also own the server process.
The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".
creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
postgres -D /usr/local/var/postgres
or
pg_ctl -D /usr/local/var/postgres -l logfile start
new-host-2:ltp mike$
@skutondo
Copy link

Thank you too, was having trouble with my user not being found so I am trying to start over from scratch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment