brew services start postgresql not working - postgresql

I have installed postgres in Mac using command
brew install postgresql#9.6
and is successfully installed
brew services start postgresql#9.6 is successful also
==> Successfully started postgresql#9.6 (label: homebrew.mxcl.postgresql#9.6)
But when I tried to access Postgres from my Mac terminal psql postgresql#9.6 it prompt me weird error
-bash: /usr/local/bin/psql: No such file or directory
Am I doing something wrong, how to open psql from my terminal
Why there is no psql file in my /usr/local/bin

The accepted answer is incorrect.
If you install postgresql#9.6 via Homebrew, the right path for the /bin folder is:
/usr/local/Cellar/postgresql#9.6/9.6.15/bin
To connect, just type: psql postgres
If you're curious about the connections details, just type \conninfo and check it.

You must to enabling Postgres command line tools.
If you are using the default terminal, you are going to want to modify the file at
~/.bash_profile
. If you are using something like Oh My Zsh you are going to want to modify the file ~/.zshrc.
To edit this file you likely need to open it via the terminal, so open your terminal and type open ~/.bash_profile. You can replace the word open with subl or whatever text editor you prefer.
Once your zbash_profile or .zshrc file is open, add the following line to the end of the file:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
After that you will need to quit and restart your terminal This is to make sure it reloads with the changes you just made.
Once you have restarted your terminal, try running psql.
psql -U postgres
You should get the following output.
psql (9.6.0)
Type "help" for help.
postgres=#
You can read more on https://www.calhoun.io/how-to-install-postgresql-9-6-on-mac-os-x/

Related

Postgresql Error in psql command not found in zsh mac

I have installed postgresql on my mac!
However when I run the command "psql" it says:
zsh: command not found: psql
I have located the location of my psql command (with other all postgres commands + pgadmin) and it is in /Users/Library/PostgreSQL/13/bin
when I do echo $PATH I get:
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Now what do I do to run psql without any error?
/Users/Library/PostgreSQL/13/bin is not in your "path"
Easy solution would be to create a symbolic link for psql in /usr/local/bin/:
ln -s /Users/Library/PostgreSQL/13/bin/psql /usr/local/bin/psql
Otherwise you can edit your profile file and extend your path to /Users/Library/PostgreSQL/13/bin
I also had the same issue and a simple solution is to restart the terminal.
It gives an opportunity for terminal to reload Postgres.
What i did to make it work:
I didn't have a .zshrc file and created one (peeped here link)
Steps for creation:
Open Terminal
Type touch ~/.zshrc to create the respective file. (touch command will create the .zshrc in your current directory but it will be hidden)
Hit Return
To view/open ~/.zshrc you can do either of two things:
Open Finder > Press Cmd+Shift+. (and you will see hidden files) my path to the file: Macintosh HD > Users > anatolii => .zshrc
Or:
Open Terminal > and type: open ~/.zshrc
Editing .zshrc
Open .zshrc in editor and pasted this line:
export PATH=/Library/PostgreSQL/15/bin:$PATH

Running PostgreSQL commands from anywhere on the terminal

First off, let me say that I'm new to both using Mac and PostgreSQL. I just installed Postgres using their installer and it was installed in /Library/Postgres/... when I tried running createdb from the terminal it returned an error createdb: command not found. I ended up using /library/postgresql/9.6/bin/createdb before I coud get it to work.
Here's my question, how do I set it so that I don't have to type in the full path again to use the createdb command.
I'd love a detailed explanation.
Thanks
First you need to execute the psql command to get into the postgresql interacive shell.
In your terminal:
psql
Postgresql interactive shell should start. In this shell
> createdb yourdatabasename;
Btw: If psql is not found you will probably need to add it to your path and restart your terminal, something like this with the path matching your machine:
export PATH=/Library/PostgreSQL/9.5/bin:$PATH

opt/local/lib/postgresql94/bin/psql: cannot execute binary file

I installed postgresql94 and the server via macports and when I try to ‘su postgres psql’ getting following error...
opt/local/lib/postgresql94/bin/psql: cannot execute binary file
Why is this? What is wrong..? I type my password correctly and then that error appears...
I found the solution from a user on #macports on irc.freenode.net
You need to run psql from a shell after running:
su -l postgres
To get a new shell running as the user postgres :)
And then it works!

PostgreSQL command psql not found, trouble adding to $PATH

I am trying to add PostgreSQL to my $PATH variable. I tried this to see where psql is
whereis psql
To which I got a null response. I do have the PostgreSQL.app installed so I clicked on "Open psql" from the GUI and it prompted the Terminal to open and display:
/Applications/Postgres.app/Contents/MacOS/bin/psql; exit;
So I tried to add the above to the $PATH variable in my ~/.bash_profile (which may have its own problems since I don't know if you can add paths with .app extensions to the $PATH) but when I restart my Terminal and do echo $PATH | grep Postgres.app I get nothin'.
Here's an approach to take help isolate problems you may have.
Step 1: See if you can add PostgreSQL to your PATH without using Bash dot files.
$ export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;
$ which psql
If this works...
Step 2: Verify that ~\.bash_profile is being sourced when a new user session is started.
Add the following to the end of your ~/.bash_profile:
echo "From bash_profile.";
Now restart Terminal.app or iTerm and see if that message appears about your prompt.
If this works...
Step 3: Add PATH to ~/.bash_profile.
In ~/.bash_profile:
export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;
Restart your terminal and run:
$ which psql
If you're not seeing:
/Applications/Postgres.app/Contents/MacOS/bin/psql
Then it might be time to scrap trying to install PostgreSQL as a Mac package and use Homebrew.
NOTE: It's psql and NOT pgsql.
From the Postgres documentation page:
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
restart your terminal and you will have it in your path.

How to use/open psql?

I have installed On windows 7 postgreSQL 9.2 version.
Now, I need use psql, so where is this terminal?
Can you tell me please how to use for example this comand: psql databasename ?
Where must be type this?
Yes, may be this is dumb question, but...
You can follow this instruction
Open the command prompt
cd C:\postgresql-9.3.0-1-windows-x64-binaries\pgsql\bin (installed directory)
Run: initdb -U postgres -A password -E utf8 -W -D POSTGRESQL_ROOT\data
give super user password (Remember that)
you wiil get the success message
Success. You can now start the database server using:
"postgres" -D "POSTGRESQL_ROOT\data"
or
"pg_ctl" -D "POSTGRESQL_ROOT\data" -l logfile start
then, you are good to start the server
To stop the server : simply ctrl + c
You can use pgAdmin tool(http://www.postgresql.org/ftp/pgadmin3/release/v1.8.4/win32/) somewhat similar like SQL Mgt Studio
Reference : http://www.petrikainulainen.net/programming/tips-and-tricks/installing-postgresql-9-1-to-windows-7-from-the-binary-zip-distribution/
The easy way to start is
Open Run Window by Winkey + R
Type services.msc
Search Postgres service based on version installed.
Click stop, start or restart the service option.