Not able to load raster to postgis - postgresql

I want to load a raster file in postgis
In command prompt I'm running
C:\Program Files\PostgreSQL\9.4\bin>raster2pgsql -I -C -s 4326 D:\Aparna\Data\PNV\pnv_new.tiff public.testraster|psql -d geodjango
I get the following error
ERROR: Unable to read raster file: D:\Aparna\Data\PNV\pnv_new.tiff
psql: 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?
received invalid response to SSL negotiation: -
My port is 5433. After going through few posts I changed the line in pg_hba.conf
from
# IPv4 local connections:
host all all 127.0.0.1/32 md5
to
# IPv4 local connections:
host all all 0.0.0.0/0 trust
but its not working. How can I solve this?

If you are not running postgres on port 5432, you need to add a -p <port> to the command, i.e. -p 5433, but according to the error message, you seem to have problems "at both ends" - both with connecting to the server and with reading the file.

Related

pgAdmin can't connect to the local database server

I've just updated pgAdmin to version 4.23 and PostgreSQL to version 12. I've also deleted all previous databases and pgAdmin installations. So it should have been a clean install (I've also cleaned up all the remains of previous versions).
Now when I'm attempting to connect to the local database server I get this before I can even type my password:
could not connect to server: Connection refused (0x0000274D/10061)Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5433? 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 5433?
The service is running, I can use command line tool and it responds correctly but I can't use pgAdmin for some reason.
>psql -V
psql (PostgreSQL) 12.3
A duplicate of your question
PostgreSQL database service
Look through this thread as it states multiple solutions
https://stackoverflow.com/questions/24917832/how-connect-postgres-to-localhost-server-using-pgadmin-on-ubuntu
To access PostgreSQL over the network
Change listen_address localhost to * in file /etc/postgresql/{version_number}/main/postgresql.conf
# - Connection Settings -
listen_addresses = '*'          # what IP address(es) to listen on;
Changes in pg_hba.conf
Add the following line in # IPv4 local connections:
host all all 0.0.0.0/0 md5
and comment
#host all all 127.0.0.1/32 md5

Cannot allow external connections in Postgres

I have a server with Postgres installed and I want to allow the connection from external IP's. Postgres works very well for local connections, then at the end of the file /var/lib/pgsql/data/postgressql.conf I added:
listen_addresses = '*'
And in the end of /var/pgsql/data/pg_hba.conf I added:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Then I restarted postgres with: sudo systemctl restart postgresql
And tried to connect with: psql -h my.db.server.ip -U postgres
And I get:
psql: could not connect to server: No existe ninguna ruta hasta el «host»
Is the server running on host "my.db.server.ip and accepting
TCP/IP connections on port 5432?
I am using Centos 7 and PostgreSQL 9.2.23
What else should I do?
Use
netstat -an | grep 5432
on the server to see if anything is listening on port 5432.
See what port is set to in postgresql.conf.
Use lsof on the PostgreSQL server process to see what sockets PostgreSQL is listening on.

Can't connect to Postgresql via 127.0.0.1

I'm trying to connect to a local instance of Postgresql using 127.0.0.1 as IP address but the connection is always denied:
⟩ psql -h 127.0.0.1 -U postgres -p 5432
psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
My pg_hba.conf looks like this:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 trust
My postgresql.conf has the following entries:
listen_addresses = 'localhost, 127.0.0.1'
port=5432
unix_socket_directories = '/private/tmp'
I can however connect via the unix socket. What else could be blocking the connection?
Not sure what happened but a hard reboot of my laptop fixed the issue.

Permission denied in postgres

I missed a bit with chmod and permissions.
And now got a lot of problems with access to folders.
If I start server I see in browser:
could not connect to server: Connection refused Is the server running
on host "localhost" (::1) and accepting TCP/IP connections on port
5432?
could not connect to server: Connection refused Is the server
running on host "localhost" (127.0.0.1) and accepting TCP/IP
connections on port 5432?
command
service --status-all
tells that postgres works
[ + ] postgresq works
Next I changed next files
sudo nano /etc/postgresql/9.5/main/postgresql.conf
#listen_addresses = 'localhost'
to
listen_addresses = 'localhost, server_ip, *'
sudo nano /etc/postgresql/9.5/main/pg_hba.conf
add
host all all server_ip/24 trust
then command
psql -U postgres -h server_ip
and error
psql: could not connect to server: Connection refused
Is the server running on host "95.213.200.26" and accepting
TCP/IP connections on port 5432?
The following chain of actions leads to a slightly different error
command
which psql
answer
/usr/bin/psql
sudo su - postgres
No directory, logging in with HOME=/
psql
psql: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Wich file permissions do I have to change here?
Check that unix_socket_directories on the server is set to the same directory (/var/run/postgresql) as the default socket directory that was configured when the client was compiled (this requires a server restart).
Alternatively, you can use the --host option of psql or set the PGHOST environment variable to tell the client to look for the socket file in /tmp, where the server creates it.
It looks like client and server are from different installations, otherwise the configured default should be the same for both. Or you have a bad PGHOST environment variable set by accident.
Check listen addres syntax. Use:
listen_addresses = '*'
For the server to listen on both localhost and the server ip.
This question is really hard. I made a great mistake with permissions 777 for / folder and whole system broke. So it is really easier delete server and start new project.

PostgreSQL Connection Refused

I have installed PostgreSQL. However everytime I try to connect through PGAdmin or through psql it gives me the below error.
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 checked the postgresql.conf file and the line: listen_addresses = '*' isn't commented out.
Also this is how my pg_hba.conf file is set:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Can anyone please advise on how I can resolve this issue?
Thanks!
Use services "start -> run -> services.msc" and look for the postgresql-[vers] service.
If it is not running try to start it, if it won't start open the event-viewer (start -> run -> eventvwr) and look for error messages relating to the PostgreSQL service.
In my case it was postgres.config. The port was somehow changed to 5433 in there and I do not remember doing it myself lol. So make sure your ports are matching up in your project vs postgres.config
pg_hba.conf.txt has to be called pg_hba.conf.
Beyond this, when you have en authentication error you will get a message similar to:
psql -U nonexistent
psql: FATAL: Peer authentication failed for user "nonexistent"
The error you are getting means most likely that PostgreSQL is not started on this server.
You can start PostgreSQL with:
service postgresql start
service postgresql status
This worked for me -
In C:\Program Files\PostgreSQL\data\postgresql.conf set listen_addresses ='localhost'
Then try -
pg_ctl -D "C:\Program Files\PostgreSQL\9.5\data" start
if already try restarting using pg_ctl
It works for me.
Remember, whatever comes after -D should be the path to where you installed PostgreSQL, to the data folder, which holds the pg_hba.conf and postgresql.conf files.
pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
Maybe you can try this.
Open cmd and insert.
"C:\Program Files\PostgreSQL\11\bin\pg_ctl.exe" runservice -N "postgresql-x64-11" -D "C:\Program Files\PostgreSQL\11\data" -w
Hit enter...