Postgres + Intellj: Fatal role can't connect to database - postgresql

Try to connect to the database through Intellj for Postgres. I just keep getting the error message. Not sure if I can include any specific details, because this is connect through IntelliJ so there's not a lot of details I can tell. The progress is running with docker and ./gradlew sDS to kick off the running volume.
The specified database user/password combination is rejected: [28000] FATAL: role "username" does not exist.

I got it to resolved, I'm having another Postgres running on the computer. Just want to mention anyone who have the same trouble as me, make sure to check if your port is not running when you run this command. If after you shut down everything with docker but they'll a port still running then you need to track down and stop other Postgres that is currently running.
lsof -nP -iTCP -sTCP:LISTEN | grep "port #"

Related

Postgres in docker - pq: SSL is not enabled on the server

Progressing with setting up a local chainlink node following the docs. When I enter:
cd ~/.chainlink-kovan && docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:1.1.0 local n
And after entering my key store password I am given an error / WARN:
2022-02-02T16:47:33.598Z [WARN] Postgres event broadcaster: reconnect attempt failed, trying again... pg/event_broadcaster.go:94 error=pq: SSL is not enabled on the server logger=EventBroadcaster
This then also leads to localhost:6688 returning nothing.
After googling this it seems it's an issue with SSL being enabled for postgres in docker, however I've tried many ways to fix but to no success. I can see my local postgres server has SSL enabled and tables have all been created. I am using WSL2 on Ubuntu to run the node with the Postrgres DB managed on Windows.
Just solved this same problem, modify your postgreSQL url to something like
postgres://username:password#localhost/db_name?sslmode=disable
Reference: SSL is not enabled on the server

Stop PostgreSQL instance by port number

Is it possible to stop postgres instance just by the port number?
I have a pgsql running on port 5433 and when I try to run:
/usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/new_cluster/data stop
This will work when I specify the -D, but let's say I don't know where the $PGDATA is and all I know is the port number this instance running on, is it possible to stop it?
/usr/pgsql-10/bin/pg_ctl -p 5433 stop
running this command result in:
waiting for server to shut down.... done
server stopped
but when I try to enter this instance by psql -p 5433 I still can get in.
*I know it might be possible doing this with systemctl but I need doing this without root permissions.
I try to do this because: I made a pg_basebackup and I want to stop the real database and run the one I just created by the pg_basebackup on the same port. just to verify that the backup is ok.
-p is not the port number in pg_ctl. The documentation says:
-p path
Specifies the location of the postgres executable. By default the postgres executable is taken from the same directory as pg_ctl, or failing that, the hard-wired installation directory. It is not necessary to use this option unless you are doing something unusual and get errors that the postgres executable was not found.
So that does nothing for pg_ctl stop, since that finds the process ID from postmaster.pid. You stopped the cluster that the environment variable PGDATA pointed to.
If you want to stop PostgreSQL by port number, connect as superuser (or a member of the pg_read_all_settings role) and run
SHOW config_file;
Then strip postgresql.conf from the output, and you have the argument to use with -D. That can easily be scripted.

CHAINLINK NODE: How might I approach fixing "unable to lock ORM" errors?

I am not overly familiar with the process of setting up a chainlink node. I have done so today, but am running into an issue. On the very last step, when attempting to start the chainlink node I put the following into the command line:
cd ~/.chainlink-kovan && docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink local n
When this runs the pulls all say "pull complete"
I am getting the following ORM errors:
2020-10-15T22:07:30Z [ERROR] unable to lock ORM: dial tcp
127.0.0.1:5432: connec t: connection refused logger/default.go:139
stacktrace=github.com/smartcontrac
tkit/chainlink/core/logger.Error
/usr/local/go/src/runtime/proc.go:203 2020-10-15T22:07:30Z [FATAL]
Unable to initialize ORM: dial tcp 127.0.0.1:5432:
connect: connection refused unable to open for gorm DB
I am not sure what might be the issue. Could someone point me in the direction I might start in the debug this issue?
[ERROR] unable to lock ORM is the default message given when the data is not able to be reached, and it also don't see another user with a lock. You can see the reason it can't connect to the ORM is because: dial tcp 127.0.0.1:5432: connec t: connection refused To fix, you can try a number of different things:
1. Try to access the postgress database using the parameters of the DATABASE_URL
If you can't get into the DB with the parameters of the DATABASE_URL there might be something wrong with that. You can see if you can connect by downloading the psql client. If on ubuntu you can use:
sudo apt-get update
sudo apt-get install postgresql-client
and then running something like psql -h IP_HERE -U USER_HERE and then entering your password
2. Add --network host for local databases
If you are running your node/database locally you'll have to add --network host to your chainlink docker command.
3. Try localhost, 172.17.0.1, or use a cloud DB if you're using a mac.
Docker is a little tricky when it comes to IPs. If you are running a local DB and you are trying to use 127.0.0.1, you may want to try localhost. On a mac, you'll run into issues since the docker gateway doesn't play nicely with macos, and easy work around is to get a database URL from a cloud database like on heroku, GCP, or AWS.
If none of these work for you, please add a comment and we can update this answer.
After reviewing Patrick's video, I noticed that that I was copying the Public IP, when in fact, the private IP from GCP is what you need you use in you command to run docker

Cannot connect PostgreSQL with psql - wrong UNIX-Domain-Socket

I'm running CentOS 7.5 and cannot setup PostgreSQL.
If I'm logged in as user postgres and type psql postgres I get the following error message:
psql: Could not connect to server: no such file or directory
does the server run locally and accepts connections on Unix-Domain-Socket "/var/run/postgresql/.s.PGSQL.5432"
However, I changed the port to 5543 (did so in etc/systemd/system/postgresql.service by including /lib/systemd/system/postgresql.service as a [Service] and setting Environment=PGPORT=5543). Note that you shouldn't change it directly in /lib/ because that will get overwritten.
So, the server looks for the wrong UNIX-Domain-Socket and does not find one (because it does not exist), but the socket for the correct port 5543 does exist according to sudo netstat -nlp:
5486/postgres /var/run/postgresql/.s.PGSQL.5543
postgresql.service is running according to systemctl status postgresql.service
Any constructive help is appreciated.
Why are you changing it in systemd and not using PostgreSQL's config file? Is that a CentOS thing?
Anyway - you can run the server on any port you like, or run multiple server instances of the same or different versions on a variety of ports. In that case though you need to tell psql what port to use.
You can set an environment variable (PGPORT), specify it with -p on the command-line or in a .psqlrc file. See the manuals for details.
Edit in response to comments:
If you want to set the PGPORT for psql, do it in the user's shell defaults or in /etc/bash... or equivalent. You could of course replace psql with an alias using your custom port or recompile the binary itself if you wanted.
I'm not sure this is really much use from a security perspective. It seems unlikely that someone can run local processes on your machine, has gained access to your postgres user password but isn't smart enough to see what port the server is running on.

Postgres service started, but can't connect. Nothing listening on port 5432

I don't know how this happened, but my postgres server (9.6.2) has stopped working locally. I seem to be able to start it up, and stop it using:
brew services start postgresql and brew services start postgresql but when I try to connect using psql I get this error:
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"?
When I try to see if anything is listening on port 5432 using lsof -i :5432 I get nothing.
Looked at other posts that say check the pg_hba.conf file, which I did, but doesn't seem to be the problem.
I ended up reinstalling postgres via homebrew. That by itself didn't do enough. I had to kill my data directory to get this to work (i.e. rm -rf /path/to/my/data/directory) and then rebuild it using initdb.
This solution obviously only works if you don't care about keeping your data (in my case, it was just data for my dev environment, so I didn't). If you do want to save a copy of your data, I you'd have to come up with something else.