How to add Postgres on Mac OS with MAMP to PATH? - postgresql

I'm following this tutorial on how to run Postgres on MAC OS X with MAMP. But I can't seem to add PostgreSQL to my PATH variable. When I run export PATH="/Library/PostgreSQL/11/bin" I get this error:
prompt_context:13: command not found: whoami
prompt_background_jobs:1: command not found: wc
prompt_background_jobs:2: command not found: awk
Here's exactly what I did:
I downloaded PostgreSQL 11.2 from Enterprise DB
I installed it using the installer:
username: postgres
password: postgres
port: 5433
The PostgreSQL folder can now be found here: /Library/PostgreSQL. Inside there's a folder called 11. Inside /Library/PostgreSQL/11 I can see the bin folder and data folder.
There's another folder inside my Applications folder called PostgreSQL 11. Here I can see a Documentation folder and some other programs I believe:
Application Stack Builder
pgAdmin 4
Reload Configuration
SQL Shell (psql)
The following error appears when I ignore setting the PATH variable and run su postgres:
su: Sorry
or sudo postgres:
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server
Also, running psql gives me this error, because PostgreSQL is not included in my environmental variables:
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"?
Note: this error asks if the server is accepting Unix domain socket with a port 5432, while I installed PostgreSQL on port 5433, what's up with that? Moving to /Library/PostgreSQL/11/bin with cd and running sudo ./psql (should run the Unix Executable file psql) gives me the same error.
Resources that didn't help me any further:
Createuser: could not connect to database postgres: FATAL: role "tom" does not exist
https://dba.stackexchange.com/questions/3005/how-to-run-psql-on-mac-os-x
Psql could not connect to server: No such file or directory, 5432 error?

When you run export PATH="/Library/PostgreSQL/11/bin" you are telling the system that all the commands you need are in that single directory. Since you also need standard system utilities like wc you also need to include the directories where they reside in your PATH. Normally you would do this to simply add the postgres directories to the list of directories searched for commands:
export PATH="/Library/PostgreSQL/11/bin:$PATH"

Related

postgresql: .pgpass not working on Windows / cygwin

I cannot get .pgpass to work on Windows/cygin
I have pgAdmin4 installed on Windows 10, psql version 12.0.
I am using cygwin, writing bash scripts to do various things to a PG database installed with a cloud provider.
If I specify these env vars in the bash script, everything works great:
export PGUSER=<pguser>
export PGPASSWORD=<pgpassword>
export PGHOSTADDR=<ip-address>
export PGPORT=5432
But if instead, I do not include those env vars in the bash script and create a .pgpass file: $HOME/.pgpass and enter a line like:
hostname:port:database:username:password
and run the script, it tries to connect to 'localhost', as if it can't find the .pgpass file.
I get this error:
Running: [./myscript.sql]
psql: error: could not connect to server: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I tried specifying explicitely in the bash script like so:
export PGPASSFILE=$HOME/.pgpass
and it still does not work, I get the same error message, it's ignoring the PGPASSFILE env variable.
I set the permissions on the .pgpass file to be 0600, and so that is not the problem.
ls -l .pgpass
-rw------- 1 <user> None 49 Feb 12 23:01 .pgpass
Go to Control Panel > Click on Administrative Tools > Open Services > Find postgresql-x64-13 and start the service.enter image description here
This worked for me.
I am using cygwin postgresql client 12.6.I tried everything mentioned here, no luck!
There is a workaround with db password on cygwin
try below psql call first, for my version of cygwin, I had to add single quote around password to make it work
psql postgresql://username:password#server:port:database
then add it to .bashrc in a function
function dbcall {
psql postgresql://username:password#server:port:database
}
and don't forget: source .bashrc
problem solved!
Another alternative to workaround this is to try WSL. Microsoft fixed a lot of WSL issues since it was first launched.
run the script, it tries to connect to 'localhost', as if it can't find the .pgpass file.
.pgpass does not tell libpq (which is what psql uses) which host to connect to. It is the opposite, libpq first determines the host, then looks for that specific host (or wildcard) within .pgpass. So it seems like the broken thing here is PGHOSTADDR, not .pgpass.

How to connect to postgres with two terminals?

I have a terminal I can connect to postgres
psql testdb
but when I open a new tab or a new terminal and tried to connect to psql an error is returned
This error returns
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5433"?
I tried creating another user and using another port
createuser testing_multiple
psql -p 5433
the same error occurs.
Your issue is probably that you're working within virtualenv. It isn't a chroot, but it sets a bunch of environment variables to fake the local environment, quite likely including the PATH and other settings.
Most likely the unix socket is at a different location to that compiled into the psql binary you're using. I'd say your PostgreSQL server socket is probably actually at /tmp/.s.PGSQL.5433, in which case export PGHOST=/tmp/ will work. Since you can connect from within the virtualenv terminal you can check though - within psql, run SHOW unix_socket_directories;. The location shown there is what you can give in PGHOST to connect to that PostgreSQL server.
The reason that export PGHOST=localhost works is that you are forcing psql (and other clients that use libpq) to connect over TCP/IP, instead of the default unix socket connection.

Openbravo postgres installation

I am trying to get a copy of Openbravo on Ubuntu for development. I am following the official guide and I get stuck by a Postgres error.
I have successfully downloaded the source code through the mercurial commands. ant setup also worked for me.
When I run the Wizard I write this information.
The problem comes when I run ant install.source:
BUILD FAILED
/home/User/openbravo/build.xml:734: The following error occurred while executing this line:
/home/User/openbravo/src-db/database/build-create.xml:50: The following error occurred while executing this line:
/home/marcguilera/openbravo/src-db/database/build-create.xml:77: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
The stacktrace is longer.
I)
First we need to change the PostgreSQL postgres user password else we will not be able to access the server. As the “postgres” Linux user, we will execute the psql commands below.
In a terminal, type:
$ sudo -u postgres psql postgres
Set a password for the "postgres" database role using the command:
\password postgres
II) Create database
To create the first database, which we will call leo, simply type:
sudo -u postgres createdb leo
III) install Server Instrumentation (for PgAdmin) for Postgresql 9.1
PgAdmin requires the installation of an add-on for full functionality. The "adminpack" addon, which it calls Server Instrumentation, is part of postgresql-contrib, so you must install that package.
Then to activate the extension,
For "Postgresql 9.1"+ install the adminpack "extension" in the "postgres" database:
$ sudo -u postgres psql
then
CREATE EXTENSION adminpack;
IV) Using pgAdmin III GUI
To get an idea of what PostgreSQL can do, you may start by firing up a graphical client. In a terminal type :
pgadmin3
You will be presented with the pgAdmin III interface.
* Click on the "Add a connection to a server" button (top left).
In the new dialog:
enter the address **127.0.0.1**
host is **jdbc:postgresql://localhost:5432/postgres**
the default database ("leo" in the example above)
your username ("postgres") and your password.
One more step is required in order to allow pgAdmin III to connect to the server, and that is to edit pg_hba.conf file and change the authentication method from peer to md5 (Will not work if you have not set the password.):
sudo nano /etc/postgresql/9.1/main/pg_hba.conf
and change the line
# Database administrative login by Unix domain socket
local all postgres peer
to
# Database administrative login by Unix domain socket
local all postgres md5
Now you should reload the server configuration changes and connect pgAdmin III to your PostgreSQL database server.
sudo /etc/init.d/postgresql reload
With this GUI you may start creating and managing databases, query the database, execute SQl etc.
https://help.ubuntu.com/community/PostgreSQL
v) Run openbravo with postgres
Just adjust the db name, user name and the passwords.
Hope that helps.

Postgresql installation

I'm going crazy with postgresql (9.1) installation on my server (debian) i have rent on gandi.net !
I did the aptitude get-install postgresql postgresql-client command.
I'm having this error when trying to execute psql command.
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I've been searching on the web. And maybe the servers are not running. I don't know how to check and how to launch them.
My postgres command doesn't work either (command not found).
Any idea?
The database engine is not running.
service postgresql start
or
/etc/init.d/postgresql start
to start the engine. I don't remember though if debian initializes the data dir automatically.

postgres server started but could not connect to server

After I lost all the data on my computer (had to have everything erased by the Apple store), I installed postgres on my Mac using Homebrew with the command brew install postgres. I then started the server (with confirmation that the server was started) and tried to create a database for a Sinatra project that uses postgres, using the command
createdb db_development
However, I got the following error:
createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
After searching online, I discovered that I might have to run the following initdb command
initdb /usr/local/var/postgres
but when I did it, I got this message
initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "braindead".
This user must also own the server process.
The database cluster will be initialized with locale "en_CA.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
So, why might postgres have confirmed the server had started at the same time I got this error could not connect to database postgres: could not connect to server: No such file or directory, and how could I fix this?
the READ.me for the project said
bundle install
createdb db_development
rake db:migrate
It either tries to connect to the postgres that comes with MacOS or PG environment variables are not set.
Try:
createdb -h localhost db_development
these are postgres environment variables for postgres. Also PostgresApp is a very convenient way to use Postgresql on Mac
Postgres has a "unix_socket_directory" setting located in postgresql.conf
Please verify that this setting exists and that the directory itself exists, then restart your server. If it doesn't exist, set it to something like /var/run (or another directory that exists) and restart the server.