Can't Run psql From Command Line After Adding To Path - macos

I had Postgres installed on OSX. Postgres.app 9.5. I wanted PGAdmin so I uninstalled it thinking that was the way. I realized I needed the dependencies and pgadmin will just allow me a GUI to work with them. So After I had pgadmin installed I installed Postgres.app again. I added the bin path to pgadmin preferences.
At this point when I start the shell from the postgres.app I \list my Db and I can see the ones I have made.
Then I run pgadmin and I can see the same databases inside the GUI.
But I cant run psql from the command line.
Not in terminal
Not in iTerm
When I paste this into the terminal I can start an active shell,
'/Applications/Postgres.app/Contents/Versions/9.6/bin'/psql -p5432 -U postgres
But when I type this in terminal or iterm I get permission denied,
/Applications/Postgres.app/Contents/Versions/9.6/bin psql
zsh: permission denied: /Applications/Postgres.app/Contents/Versions/9.6/bin psql
When I run with sudo I get command not found.
I added this to my ~/.bash_profile
export PATH="/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH"
Then I ran,
source ~/.bashrc
I also quit out of terminal and iterm but when I run psql I still get command not found.
Any help from here would be great. I want to add psql to my path so I can do things like,
psql --Version
etc.

Related

Command not found: psql

After following the installation guide here: https://postgresapp.com/, I ran the command in step 3 to configure my path and was presented with this:
/Applications/Postgres.app/Contents/Versions/latest/bin
However, after then typing which psql I get psql not found, and when trying to start my local database get command not found: psql.
I am able to start up the PostgreSQL app and initialize, but can't seem to run any commands in the terminal associated with psql.

-bash: initdb: command not found

I have installed PostgreSQL using the EnterpriseDB installation.
I ran sudo ./postgresql-9.3.5-3-osx.app/Contents/MacOS/installbuilder.sh --mode unattended and then ran open /Applications/TextEdit.app .profile to edit my .profile file newly created in /Users/Dhruv to add the line source /Library/PostgreSQL/9.3/pg_env.sh.
Running createuser Dhruv --pwprompt --username=postgres I got
-bash: createuser: command not found
Then running unknown-88-1f-a1-1b-c2-ec:9.3 dhruv$ sudo -u postgres /bin/createuser and various other methods I was able to set up something using some sort of password prompt. I know this later because using sudo -u postgres /Library/PostgreSQL/9.3/bin/createuser I got
createuser: creation of new role failed: ERROR: role "postgres" already exists
Running then initdb -D /Library/PostgreSQL/9.3/data I get
-bash: initdb: command not found.
Similiarly, if I try the same thing but while connected to postgres, sudo su - postgres and then initdb -D /Library/PostgreSQL/9.3/data I get again
-bash: initdb: command not found.
At a loss at what to do. 1) how do I know details of this supposed role "postgres" I created magically and 2) why is initdb not working?
How I fixed this is run brew doctor, and you might see the postgresql un der the Warning: that indicates there's unlinked kegs in your Cellar.
Try to run brew link postgresql. It will show some symlinks got created. Then run init db ... again.
Hope this help!
Who are you logged in as?
When you do sudo or su -, it will run init scripts for root, such as .bashrc and .bash_profile.
These may set up difference executable search paths between root, postgres, and you.
Try something like sudo initdb, or su - postgres -c initdb ... whichever user has the paths constructed correctly, so that the path gets set up.
You could also duplicate the path/lib creation code in your own environment, but that will break if it is ever changed.
Same thing happened to me. I'm new to OS X coming from Linux, here's what I had to do. I installed postgres via homebrew and when I did so I noticed it put everything it download to: /usr/local/Cellar/postgresql/($postgres_version)/
When I cd'd into that folder I saw a directory named bin so I cd'd and saw initdb right there. So I had to then add this to my path so I could use the command:
$ export PATH=/usr/local/Cellar/postgresql/9.4.4/bin:$PATH
hope that helps you

Unable to map path to postresql after installation of Postgres 9.3 to mac

After installing Postgresql by dragging folder into my applications folder I am unable to get commands to work in the terminal and unable to add the path so that is shows up using the command $ echo $PATH.
Postgres starts in the terminal using the elephant icon on the system tray and selecting "open psql" so I believe it installed correctly.
I tried adding all different combinations of the following lines to my .bash_profile
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
then
PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
then
export PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin
and finally
export PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin
after each attempt I ran $ source $HOME/.bash_profile and then checked path and/or tried $psql $ which psql to no avail.
Also tried adding lines to .bashrc , .profile and .zshrc without luck.
The path to the executable commands bin folder in the app (psql, createdb, createlang, etc..) is
$ /Applications/Postgres93.app/Contents/MacOS/bin
Any help would be greatly appreciated!
running OSX 10.9.1
https://superuser.com/questions/707222/unable-to-get-postgresql-commands-to-work-in-terminal
answered at the link above by zelanix https://superuser.com/users/293259/zelanix

connect failed mongo db on mac osx

i'm trying to learn mongo db on my mac. I installed mondgo db using homebrew and it appeard successful. I created the dir /data/db. when I type mongo into the terminal I get:
Error: couldn't connect to server [a bunch of numbers] at src/mongo/shell/mongo.js:145 exception:connect failed
I looked at the following answer on SO: Installing and Running MongoDB on OSX
in the check answer it says:
1) Start a terminal for your mongo server
2)Go to mongo/bin directory
What does it mean to start a terminal for your server? does that mean just open up a new terminal window?
Where can I find the mongo/bin directory?
Any other suggestions on getting mondoDB up and running would be appreciated.
you should read the documentation here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
And follow the instructions.
In this case the [bunch of numbers] are the hostname/ip and port number that the binary mongo has tried to connect to. What it's telling you is that there is no mongod binary listening on the hostname and port that mongo is trying to connect to.
You will need to start mongod before you are able to connect to it with a mongo shell. The documentation above outlines this further.
If you use homebrew the mongodb binaries will automatically be put on your path which means you won't need to cd into another directory like mongo/bin.
Good luck.
Probably you run the mongodb first time. Based on the documentation you must follow a few steps and then you are ready to go.
First, create main db directory:
sudo mkdir -p /data/db
Make sure that you have a read and write permission on that directory:
sudo chown `id -u` /data/db
And to listen to default port, run:
mongod
Finally keep in mind that after the run "mongod" command do not close console tab. Open a new tab (Cmd + T) and run other commands on the new window. To close the mongod session simply hit the Ctrl + C on the previous tab.
when everything mentioned above did not work. I did the following thing (in Mac)
cd ~
mkdir -p data/db
After creating directory in home(which will be definitely allowed) most imp command is below
mongod --dbpath ~/data/db &
So that it could take the path of db which was in home directory (as we are not able to create in / dir.
To avoid it running frequently, put the above command in .bash_profile file in home directory so that it will automatically run the above command whenever we try to use terminal in Mac
Note: Whenever we open the terminal it will execute the above command so that we can access the mongodb (I understand this should be taken place in background but it works fine)
We need to press enter/return key to get the regular command line terminal and continue doing our work
These steps worked for me well on Mac, you can give a shot, make sure you install brew first and put these lines in terminal line by line:
brew update
brew install mongodb
brew install mongodb --with-openssl
brew install mongodb --devel
sudo mkdir -p /data/db
sudo chown -R [your username] /data/db
(Replace with your username with what you can get by typing whoami in the terminal)
mongod
Run you app, for example localhost:8000

Why can't I get the postgresql server to run?

Ok. I have been trying to solve this problem for several days. I installed, uninstalled, and reinstalled Postgresql 3 times. I followed precisely the instructions in this forum: https://dba.stackexchange.com/questions/42048/cant-connect-to-the-postgres-server-ls-tmp-s-pgsql-5432-no-such-file-or-dir
I found this solution in many forums, so I tried to run:
$ mkdir /var/pgsql_socket/
$ sudo mkdir /var/pgsql_socket/
$ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
But this didn't work. When I try to start the server it still says there is another one running and then proceeds to fail every time I try to create a database or type "psql"
I then tried to run the following in order to change the path of the commands from OS X's builtin version of postgres to my version and it seemed to work:
$ cd /usr/local/bin
$ rm postgres
$ ln -s /Library/PostgreSQL/9.2/bin/postgres postgres
$ rm psql
$ ln -s /Library/PostgreSQL/9.2/bin/psql psql
$ rm pg_ctl
$ ln -s /Library/PostgreSQL/9.2/bin/pg_ctl pg_ctl
So then I ran the following to create a user for postgres:
$ sudo -u postgres createuser --superuser $Sarah
$ sudo -u postgres createuser --superuser user_sarah
$ sudo -u postgres psql postgres
But it kept saying "unknown user postgres"
I then tried to install the Ruby pg gem, but that also failed, saying there was a problem with necessary libraries.
I have saved a text file of everything I tried to do in the terminal. Let me know if I should post that. Thanks.
update:
When I try to run this:
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
I get this:
-bash: /usr/local/bin/pg_ctl: No such file or directory
Which is different from a lot of other errors that I have seen posted on this problem.
first, you should verify that there is no postmaster running: ps -ef | grep postmaster. once you've verified the postmaster is not running, you should look into the postgresql command initd. Depending on your server installation, it may or may not be installed. You need to create a database before attempting to start postgres. It sounds to me like you got an installation that didn't install the main postgresql commands to /usr/bin, pg_ctl being one of these.
FYI: the postgres account is not a login account and is automatically created when installing postgresql, so it should be there if you had a good installation. You cannot sudo as postgres if postgres is not in the sudoers file.
The homebrew install of PostgreSQL does not create or need a postgres account, so all the mentions of doing sudo -u postgresor ps -fu postgres don't apply to your case.
The command brew info postgresql outputs various information about to start and stop it, you may read them. By contrast you don't want to put blind faith into what random users tell about how they "fixed" their non-working installation. In fact, the web carries a shocking amount of bad advice concerning PostgreSQL on MacOS X, and to me the answer you linked on dba.se is among them. It's wrong from start to finish, and you should note that it was not accepted as an answer. Certainly the author means well, but he fails to see that his own context can't be generalized to other installations.
The worst part is the suggestion to delete in /usr/local/bin/ the binaries postgres, psql, pg_ctl and soft-linking them into supposed equivalents inside /Library/PostgreSQL/9.2/bin/.
To me it just breaks the homebrew install.
No wonder that after doing this you get this error:
/usr/local/bin/pg_ctl: No such file or directory
So my answer would be to reinstall postgresql with brew to restart from a clean state, then make sure that all postgres commands you launch are from /usr/local/bin, and always first read the server log file passed to pg_ctl if you have any doubt on anything PG-related.

Resources