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!
Related
I'm a web development student and struggling to solve this problem on my own, any help would be appreciated!
Note that I'm working in an Amazon Cloud9 instance. My problem is that when I try to import an SQL file into a PostgreSQL database using the following command:
$ psql -d my_database < file_to_import.sql
I get the following error:
https:/raw.githubusercontent.com/...[removed for privacy]: No such file or directory
I know the file exists, because I'm able to navigate to it. I've tried copying the contents of the file into a new file on my desktop and then inserting the path to that file in the place of "file_to_import.sql" but that's not working either. I get the same error.
I've also tried importing via this template:
my_database=# \i ~/some/files/file_to_import.sql
But I get the same error. What's gone wrong here?
Thanks in advance!
These issues can be occurred because lack of permissions for a file try one of the following commands with the proper elevated permissions. For number one, you don't need sudo but if that didn't work try the second one of them should help you
1. psql -h hostname -d databasename -U username -f file.sql
2. sudo -u postgres psql db_name < 'file_path'
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/
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
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.
I am trying to restore the postgres sql data from a file . I am trying to do so but it is not importing .
Here is the command which i am using:
postgres-# psql -hlocalhost -p5432 -u postgres -d test -f C:/wamp/www/test/database_backups/backup004.sql
Please help me what I am doing wrong .
I am using windows and the above command does not throws any error but it does not import data.
Regards
Surjan
The only immediate thing I can see there is the capitilsation of -u for username (should be -U).
Correction: You're typing the command line into the psql shell.
You should exit to the CMD.EXE shell, and try the command there. With the correct capitalisation of -U, by the way.
OR, use this to replay the script into that psql shell:
\i C:/wamp/www/test/database_backups/backup004.sql
The forward slashes don't cause a problem on my Windows machine.