Installing PostgreSQL on Mac OS X - macos

I am starting to use PostgreSQL on my Mac but I am stumped as to how I should go about it
I tried out instructions given in the below sites :
http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/
https://www.codementor.io/devops/tutorial/getting-started-postgresql-server-mac-osx
https://gist.github.com/sgnl/609557ebacd3378f3b72
but to little avail.
Here is my terminal log:-
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ brew install postgresql
Updating Homebrew...
Warning: postgresql 9.6.5 is already installed
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ postgres --version
postgres (PostgreSQL) 9.3.5
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ psql postgres
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ which postgresql
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ which postgres
/usr/local/php5/bin/postgres
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ postgres -D /usr/local/var/postgres
LOG: unrecognized configuration parameter "dynamic_shared_memory_type" in file "/usr/local/var/postgres/postgresql.conf" line 126
FATAL: configuration file "/usr/local/var/postgres/postgresql.conf" contains errors
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ postgres -D
/usr/local/php5/bin/postgres
postgres cannot access the server configuration file
"/usr/local/php5/bin/postgres/postgresql.conf": Not a directory
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
server starting
LOG: unrecognized configuration parameter "dynamic_shared_memory_type" in file "/usr/local/var/postgres/postgresql.conf" line 126
FATAL: configuration file "/usr/local/var/postgres/postgresql.conf" contains errors
Service `postgresql` already started, use `brew services restart
postgresql` to restart.
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$ postgres -V
postgres (PostgreSQL) 9.3.5
Pavan7Vasans-MacBook-Pro:~ pavan7vasan$
what has me in a fix is that despite the latest version of PostgreSQL being installed through homebrew, the current version is 9.3.5
Is this because of an older version of PostgreSQL present as shown through the which postgres command is conflicting?
Are all the above errors due to the older version still being the current version?
If possible, how do I change the version to the latest version?
Please do tell me what is to be done

Related

Redis can't start due to tcp-backlog

I am using the osx and trying to install redis through brew
brew install redis
==> Downloading http://download.redis.io/releases/redis-2.8.17.tar.gz
Already downloaded: /Library/Caches/Homebrew/redis-2.8.17.tar.gz
==> make -C /private/tmp/redis-WEL8AT/redis-2.8.17/src CC=clang
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
At last I have installed redis, but when I run it in the way of
redis-server /usr/local/etc/redis.conf
there is error message,
*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 54
>>> 'tcp-backlog 511'
Bad directive or wrong number of arguments
I learned from Redis tcp-backlog to uncomment the redis.conf in that line.
but still more errors on other lines come again.
How do I solve it ?
Check if you have installed redis twice. I my case I had another redis installation from anaconda with version 2.6.9:
$ which redis-server
/Users/<username>/anaconda/bin/redis-server
$ redis-server -v
Redis server v=2.6.9 sha=00000000:0 malloc=libc bits=64
Homebrew instead will install the redis-server to a different place:
$ /usr/local/bin/redis-server -v
Redis server v=3.0.1 sha=00000000:0 malloc=libc bits=64 build=bf58331b4c8133f5
So to start the homebrew version with the homebrew config file do
$ /usr/local/bin/redis-server /usr/local/etc/redis.conf
I had similar problem due to a config file left over from previous redis versions. Uninstalling all redis versions and reinstalling the latest worked (also, don't forget to update brew before installing redis):
brew uninstall redis --force
brew update
brew install redis
You should now be able to start it.

starting postgres server on Mac

I am having this issue third or forth time where after restarting my Mac (Yosemite and same thing with previous OSX version) postgres server doesn't start. I had installed my postgres following this link. Any idea why this consistently occurs after every restart?
typing psql it gives
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I just fixed this on my mac. I used homebrew to install postgres. These are the steps I took to get up and running again.
First check the status of the postgresql service:
pg_ctl -D /usr/local/var/postgres status
if you see this pg_ctl: no server running, unload the launch agent:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
then move your existing postgres data (move rather than delete - cheap insurance):
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
then initialize your postgres database:
initdb /usr/local/var/postgres -E utf8
then load your launch agent:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
OR start it:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Now check the status again:
pg_ctl -D /usr/local/var/postgres status
if you see something like this, you are good to go.
pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"
Then you can go into your postgres database:
psql -d postgres
Also after that you need to add postgress Role.
To Resolve missing postgres Role error
To start postgres server on mac:
install postgres with brew
brew install postgres
ensure you have permissions for /usr/local/postgres
sudo chown -R `whoami` /usr/local
then init the db:
initdb /usr/local/var/postgres
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
To load postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
To check your version:
psql --version
And to access postgres
psql -d postgres

Erros in installing PostgreSQL using homebrew

I'm using Mac OS X 10.8.5 and trying to install postgreSQL using homebrew. I've fixed several errors and warnings which have occurred when I ran brew info postgresql. However, I don't know how to fix the rest of the problems.
$brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 40M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
==> Dependencies
Required: readline ✔
Recommended: ossp-uuid ✔
==> Options
--32-bit
Build 32-bit only
--enable-dtrace
Build with DTrace support
--no-perl
Build without Perl support
--no-tcl
Build without Tcl support
--without-ossp-uuid
Build without ossp-uuid support
--without-python
Build without python support
==> Caveats
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/Homebrew/homebrew/issues/issue/2510
To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
http://www.postgresql.org/docs/9.3/static/upgrading.html
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
When I run server, I get:
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I've uninstalled postgresql and reinstalled but seems like I wasn't able to remove the postgresql 8.x version.
I've read several different posts to install and run postgreSQL properly and tried what they've suggested but nothing seems to be working for me.
Installing PostgreSQL in Mac OS X El Capitan using homebrew
First check the 'owner' of the folder '/usr/local' by using this command:
$ ls -la '/usr'
If the owner of the file is 'root', run this command to change the owner to your currently logged user:
$ sudo chown -R `whoami` /usr/local
Install PostgreSQL using homebrew:
$ brew update
$ brew doctor
$ brew install postgresql#15
and that's it!
Uninstall PostgreSQL using homebrew:
$ brew uninstall postgres
then remove this folder: '/usr/local/var/postgres' and then change back the owner of your local
local folder to:
$ sudo chown -R root /usr/local
How to:
List brew services: $ brew services list
Run brew services: $ brew services start <service_name>
ex: $ brew services start postgresql
Stop brew serices: $ brew services stop <service_name>
Logging in to PostgreSQL for the first time:
1.) Run the postgres: $ brew services star postgresql
2.) Create a db using your username: $ createdb `whoami`
3.) Login to postgres: $ psql
To quit psql, just type: \q
4.) Create database (using terminal):
$ createdb <db_name>
psql tutorial:
http://blog.trackets.com/2013/08/19/postgresql-basics-by-example.html
http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/
Optional, installing pgAdmin:
1.) Download pdadmin: https://www.pgadmin.org/download/macosx.php
2.) Press ctrl+click then open to run the dmg file then drag it to your
Application folder. ctrl+click the pdadmin to run it so that it won't
ask for that annoying question again.
Login in to pgAdmin:
Note: Use your username and password when you installed your postgres for first login
then create a new user with privileges later or just change your password from
'File -> Change Password...'
Your Ruby code is apparently linked against the system version of PostgreSQL, which looks for a socket in /var/pgsql_socket. The Homebrew version would look in /tmp. (At this point, make sure that a file like /tmp/.s.PGSQL.5432 exists.) To work around this, you can tell your code to connect to the Homebrew version by specifying /tmp with the "host" option, however your code spells that.
In the future, make sure your Ruby gems are linked against the Homebrew version. Perhaps just uninstalling and reinstalling with the right paths set would do it.

Mismatching pg_dump on MacOS X

Locally, it appears that I have Postgresql 9.2.4 installed. I am guessing based off the last error message I received that I do not have the latest version:
pg_dump: server version: 9.3.1; pg_dump version: 9.2.4
pg_dump: aborting because of server version mismatch
On other posts here, what was told to do was to add the following the the .profile and then run the command:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
. ~/.profile
which did not work.
2 weeks ago, I installed Postgresql with the simple command:
brew install postgresql
and that gave me the version I currently have. It appears as I don't have the latest version then.
How can I a) upgrade to 9.3.1 (which is what the server version looks to be) or b) do one of these fixes like the one I attempted above which did not work.
I am very new to Postgresql so a step by step would be very helpful for me.
brew upgrade postgresql
brew link --overwrite postgresql
Solved by adding this at the end of my ~/.bash_profile ( or ~/.zshrc for zsh)
export PG_DUMP="/Applications/Postgres.app/Contents/Versions/9.6/bin/"
PATH=$PG_DUMP:$PATH
Don't forget to run (for bash shell)
$ source ~/.bash_profile
or (for zsh)
$ source ~/.zshrc
You can check the path of pg_dump by running
$ which pg_dump
==> /Applications/Postgres.app/Contents/Versions/9.6/bin//pg_dump
MacOS Mojave (10.14.2)
Postgres.app (2.1.5)
PostgreSQL 9.6
There are upgrade instructions you have to follow between Postgresql 9.2 and 9.3...
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres92
brew update
brew upgrade postgresql
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/9.2.4/bin -B /usr/local/Cellar/postgresql/9.3.1/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Install SQlite3 on os x

Trying to install symfony2 and I get the following message
You need to enable either the SQLite3 or PDO_SQLite extension for the
profiler to run properly
I installed it via macports
$ sudo port install sqlite3
Password:
Warning: port definitions are more than two weeks old, consider using selfupdate
---> Computing dependencies for sqlite3
---> Deactivating sqlite3 #3.7.1_0+universal
---> Cleaning sqlite3
---> Activating sqlite3 #3.7.1_0
---> Cleaning sqlite3
imac27:bin ed_lea$ sudo apachectl graceful
check that it exists
$ which sqlite3
/opt/local/bin/sqlite3
and it's in my path
$ sqlite3
SQLite version 3.7.1
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
but I'm still getting the same error.
I guess PHP is not able to see it but I don't know how to add it. I'm not using the default version of PHP that came with os x. Here's a link to my php.ini file (large image) http://cl.ly/2J2X0A0n1W2R1T0x3f30
Maybe you should try run corresponding port installation like here?

Resources