It seems like I have it set up, I have my database.yml using postgres, and I can connect the database with pgadmin III, but when I tried using the psql command to test what version, it says that is is not recognized? Any idea what I should be doing?
I'm using windows and using command prompt with Ruby on Rails. Using PostgreSQL 9.2 installed with the EnterpriseDB one-click installer.
Assuming you installed PostgreSQL on Windows with the PostgreSQL "One-click" installer packaged by EnterpriseDB, psql is not added to the PATH automatically. That's partly because adding it to the path could otherwise cause confusion when people have multiple versions of PostgreSQL installed.
You need to specify the full explicit path to psql, eg:
"%PROGRAMFILES%\Postgresql\9.2\bin\psql.exe"
or add psql to the user PATH environment variable, see eg this guide.
Open Command Line
psql --version
if on above line psql version is not displayed, then follow below steps
(For Windows 7 OS)
Mycomputer->Properties->Advanced System Settings->EnvironmentVariables->Path->Edit->
(Donot remove any existing Path)
Add this
;C:\Program Files\PostgreSQL\9.5\bin;C:\Program Files\PostgreSQL\9.5\lib
save it then
Reopen Command Prompt and repeat
psql --version
C:\Users\rumi>psql --version
psql (PostgreSQL) 9.5.0
it is because there should not be space between the ; and your psql path so it should be like *****;C:\Program Files\PostgreSQL\9.2\bin\.
If there is a space after ******; then it will not work. You can actually type %PATH%in your cmd prompt and see how your environment variable and space looks like. I tried both cases for you, the first with space had the same error you mentioned and the second without space worked.
You need to set both the bin AND the lib path in your PATH environment variable separated by semicolons:
%PROGRAMFILES%\Postgresql\9.2\bin;%PROGRAMFILES%\Postgresql\9.2\lib
Related
I'm trying to pull a production database locally for my rails app. My local postgres version was too low so I needed to update to Postgresql 9.6.5 from 9.4.1.
I installed Postgres 9.6.6 via Homebrew as such:
brew install postgresql#9.6
Then ran:
brew services start postgresql#9.6
However, when I try to do pg_dump I get -bash: pg_dump: command not found.
I also tried updating my path as such:
export PATH="/usr/local/Cellar/postgresql\#9.6/9.6.6/bin:$PATH"
Any idea what I need to do to get pg_dump to work?
Adding this to my ~/.bash_profile did the trick:
export PATH=/usr/local/Cellar/postgresql\#9.6/9.6.6/bin:$PATH
For those who have this issue on Mac even though Postgres path is correctly added on your .bash_profile I found that running pg_dump directly from the Terminal does the job.
Just open your Terminal and type:
pg_dump -U username your_database > db_dump.bak
I tried the ff approach and I got the same error:
sudo su - postgres
pg_dump -U username your_database > db_dump.bak
bash: pg_dump: command not found
If you installed PostgreSQL by pgadmin4 in Mac, you could find the pg tool in
/Library/PostgreSQL/{version}/bin/
Couldn't get path to work in Cygwin but could browse to my pg bin directory (C:\Program Files\PostgreSQL\9.6\bin) and run it directly from there.
For windows what worked for me is to add the Postgres to global vars from env, not ~/.bash_profile,
Go to Edit the system environment variables
Then Environement variables
Then Path then add the location of bin of postgres in my case C:\Program Files\PostgreSQL\14\bin\
Click ok on each open window
Close and reopen your visual code
Run your command
See Setting Windows PATH for Postgres tools for more details
How do I specify which version of postgres rails use? When I run puma and go to localhost:3000 I get a an error
PG::ConnectionBad
fe_sendauth: no password supplied
I think the copy being used may be the manual install 9.3, as when I run:
/usr/local/Cellar/postgresql/9.4.1/bin/pg_ctl -D /usr/local/var/postgres start
I get the error:
stgres start
server starting
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.1.
I found three copies of pg_hba.conf on my system:
/Library/PostgreSQL/9.3/data/pg_hba.conf
/Users/lasernite/Library/Application Support/Postgres/var-9.4/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf
The first one I believe was from a manual install at some point. The second one is probably just some supporting copy/ignorable, and the third one is a homebrew install.
How can I make rails use the homebrew postgres install, even if it means wiping the local database? Which is fine so long as the production on heroku is instact.
I've been stuck for several days on reconfiguring my development environment from sqlite to postgres, which is very problematic as I have a production db and site live now, which is forcing me to do some code pushes without being able to verify functionality locally, but for the most part has totally crippled my ability to do any development.
Please help me!
It looks like the problem is that you're starting 9.4.1 when the database was created by 9.3.x.
The version of posgres that Rails uses should be whichever one is running. So if you want to start postgres in version 9.3.x, then you should start that version. But you have to specify the correct path for that version.
What output do you get for these?
> initdb --version
> pg_ctl --version
> postgres --version
> psql --version
It should all be the same. If it says 9.4.x and you want to use that version, then you can re-init the database like so: initdb -D /usr/local/var/postgres-4.1 and then you can start postgres postgres -D /usr/local/var/postgres-4.1. Doing it this way, you'll probably lose your local database since it sounds like that data was created by 9.3.x.
Alternatively, if those output 9.3.x, then you should just be able to use the commands without the full path to the binary: postgres -D /usr/local/var/postgres.
If you're using 9.4.x and you want to keep using 9.3.x, then try which postgres. It's probably pointing to /usr/local/bin. Then make sure that that is just a link to the homebrew version. ls -la /usr/local/bin | grep "postgres ->".
If you're using the homebrew version, you can do brew switch postgres 9.3.x to tell homebrew to use that version. Then you should be able to start postgres with postgres -D /var/local/var/postgres.
I am using Putty to connect to my localhost, and I don't have any problems apparently, however, when I run command rails s to start my rails 4.0.0 application from Putty, it gives me this message:
jose#jose-laptop:~/rails/dedicated-agenda$ rails s
The program 'rails' can be found in the following packages:
ruby-railties-3.2
ruby-railties-4.0
Try: sudo apt-get install
I don't get that message from the terminal though, the application starts running just fine.
I had to reinstall ubuntu so I upgraded to ubuntu 14.04 just in case you need to know.
I don't know if I am missing something in my ssh settings or how could I use rails s from Putty.
Thanks in advance.
Your PATH environment variable is set differently when you are executing programs in an interactive shell and by ssh(using putty).
Use absolute path of the program to not depend on the PATH variable.
You can also set the right PATH variable at ~/.profile file and load the updated variables using the command source ~/.profile.
Now, you should be able to run the command.
You can use the command
>which rails
to see where rails is installed on your working session.
Then you need to make sure that is in your path when you ssh in.
If you are ssh'ing in as a different use then that user may not have permission to see the rails executable.
I've got a fairly simple question I guess. I'm working on a Ruby on Rails app.
I'm trying to switch to PostgreSQL thanks to Heroku.
In my database.yml file it states:
Install PostgreSQL and put its /bin directory on your path.
My question is how do I put PostgreSQL's /bin directory on my path? Exactly which file do I modify and how?
I imagine this is my issue since when I run the "rails db" command i get:
"Couldn't find database client: psql,psql.exe. Check your $PATH and try again."
Thanks everyone!
Robin.
Append the directory to system PATH (not user PATH) by Environment Variables, using a semicolon to separate it from the previous entry.
You can find it from control pannel -> system -> Advanced -> Environment Variables
Ran into the same issue and tried the solution mentioned here
[user#host user]$
psql
bash: psql: command not found
[user#host user]$
echo $PATH
/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin
[user#host user]$
export PATH=$PATH:/usr/local/pgsql/bin
[user#host user]$
psql testdb
Should do the trick.
You need to install Postgres first then add the path to system properties > environment variables > in system variables section you will see PATH variable
This is my preferred way of adding a new location to the PATH environment variable (on modern Red-Hat-based systems):
echo 'export PATH="/usr/pgsql-9.3/bin:$PATH"' | sudo tee /etc/profile.d/pgsql.sh
PATH is a colon : separated list of directories that are search, in order, for a called program.
Profile configurations under /etc are persistent for all users (but require the active shell to source them to take effect).
The version number is tacked on to the PostgreSQL directory when it is installed from their repository.
I'm trying to setup a new app with postgresql so I can deploy with Heroku. However, when I run the app using 'rails server' my welcome to rails screen gives this error:
PG::Error
could not connect to server: Permission denied Is the server running
locally and accepting connections on Unix domain socket
"/var/pgsql_socket/.s.PGSQL.5432"?
I'm sure this is the same issue as is covered here:
Repairing Postgresql after upgrading to OSX 10.7 Lion
But the fix by John Wang doesn't work.
I've tried adding 'export PATH=/usr/local/bin:$PATH' to the .bash_profile, .bashrc and .zshrc, none of which change the outcome. Calling which psql always returns /usr/bin/psql.
What am I doing wrong here? Any help would be much appreciated!
edit
Running /usr/local/bin/psql gives the same error and running echo $PATH gives:
/opt/local/bin:/opt/local/sbin:/Users/dave/.rvm/gems/ruby-1.9.3-p194/bin:/Users/dave/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/dave/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/dave/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/.rvm/bin
What happens if you run your locally installed psql directly?
/usr/local/bin/psql ...
If that works then it's the path you need to change. You can just try running the export in a terminal, then which psql. If that doesn't pick up the right psql then check the export worked with
echo $PATH
I'm not sure which .xxrc file you'll need to update then - not got a mac to hand I'm afraid, but at least you'll know the command will work.
Oh - I keep several different versions of PostgreSQL around and find it useful to have some aliases set up:
alias psql90='/usr/local/pgsql90/bin/psql -p 5490'
alias psql84='/usr/local/pgsql84/bin/psql -p 5484'
alias pg_dump90=...
Your $PATH is just a list of directories to check separated by ":". It starts /opt/local/bin rather than /usr/local/bin and if you look further along you'll see /usr/bin coming before /usr/local/bin. So - we need to do two things:
Find out which psql we actually want
Make sure we can edit our PATH
Firstly - find your postgresql.conf file and check what port you are running on. There are three items of interest: listen_addresses, port and unix_socket_directory. Then we'll see if there's a socket there.
ls -a <your unix_socket_directory>
You should see a "file" something like ".s.PGSQL.5432" where the 5432 is the port number from your config file. If there's no such file, it's not running and it's time to get it running. You may need to change the port number in the config file if it matches Apple's existing usage.
Then find what psql installations exist
find /usr -type f -name psql
find /opt -type f -name psql
Try and figure out which one you need, perhaps add --version to help.
Then, let's see about editing your PATH. You must have some changes in your settings file anyway, so let's see if we can find where that setting is.
grep -l 'local/bin' ~/.*rc
That should list filenames containing local/bin - have a look and see if they are editing your PATH.