Perl DBI: connect to REMOTE PostgreSQL db still complains about local socket file - postgresql

I'm trying to use DBIx::Class to connect to a remote PostgreSQL db.
My connect string: "DBI:Pg:database=asterisk:host=example.com:hostaddr=10.10.10.10:port=5432", $user, $pass
example.com does resolve to '10.10.10.10', swapping both to the IP or having only host=IP all result in
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"? at /usr/local/share/perl/5.10.1/DBIx/Class/Storage/DBI.pm line 1489. at db-access.pl line 26
On this debian I don't have or want postgresql, I do have libdbd-pg-perl however. And DBI->available_drivers says that I do have Pg (It didn't before I installed the library).
How can I find out what it's trying to do and do I need anything else installing? The server in question is configured to allow connections from 10.100.* addresses which the machine running this code is on and I can connect to it with tools such as PSequel and pgAdmin on my workstation (same network) with the db user in question.

"DBI:Pg:database=asterisk:host=example.com:hostaddr=10.10.10.10:port=5432"
That should be:
"DBI:Pg:database=asterisk;host=example.com;hostaddr=10.10.10.10;port=5432"
Only the first two separators are colons. The rest of them should be semi-colons.

Related

PostgreSQL: could not connect to server

I have an issue that I've been trying to fix but after reading articles, I couldn't do anything about it. The problem is as it follows:
I just installed Apache, php and MySQL on a VPS. Then I had to install PostgreSQL and set up a database and a new user. After running the psql command, I got the following output:
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"?
So, my question is how do I fix this. I'd be grateful if I receive some feedback.

Remotely connecting to postgresql server works from my computer does not work from hosting provider's

There is a PostgreSQL server on a Windows computer that I need to access remotely. It's not on the local network. I'm trying to connect to it with pg_pconnect. I have an AMP stack with PHP 7.1.23 on my local Mac computer and I can connect to it just fine. (The connection works, I can make queries, etc.) When I upload the same script to a hosting provider (LAMP stack with PHP 7.1.22) the script does not work anymore.
Warning: pg_pconnect(): Unable to connect to PostgreSQL server: could not connect to server: Connection refused
Is the server running on host "x.x.x.x" and accepting
TCP/IP connections on port 5432? in /path/to/my-script on line 42
I would think that the SQL server does not allow remote connections if it didn't allow the connection from my computer either. But to that server both connections would be remote, right? So how can it allow one and not allow the other?
Turned out that the hosting provider had to whitelist the IP address first. That's why it didn't work.

Connect clients to portable PostgreSQL server

First of all: my only experience with SQL is by SQLite which is a server-less engine. I'm new on all this client/server story.
Summarizing my goal: I need to read/write from/into a PosgreSQL database from different computers. Those computers (all with Windows 7 or 10 installed) share the same network but I cannot install any software on them.
My idea was to download the portable PostgreSQL server and save it in a network shared directory (e.g. Y:\PortableProject) so all computers have access to the executable files and to the Data folder containing the databases. Suppose the network IP is 192.170.1.200 (from ipconfig command), here are the steps I tried to do so far:
In order to allow IP 192.170.1.200 being a host, open pg_hba.conf file and add the following line in the EOF
host all all 192.170.1.200/32 trust
In order to give permission to all computers accessing the server, open postgresql.conf and update listen_addresses to *
listen_addresses = '*'
Open the command prompt in one computer (e.g. computer A) and start the server from a prompt with the following command:
"Y:\PortableProject\PostgreSQLPortable\App\PgSQL\bin\pg_ctl.exe" start -D "Y:\PortableProject\PostgreSQLPortable\Data\data"
Proceed with writing and reading in all computers. E.g., on computer B, open its prompt command and read all information on table tabtest from database dbtest (supposing they exist) with the command:
"Y:\PortableProject\PostgreSQLPortable\App\PgSQL\bin\psql.exe" -h 192.170.1.200 -p 5432 -U postgres -d dbtest -c "SELECT * FROM tabtest"
Close the connection on computer A:
"Y:\PortableProject\PostgreSQLPortable\App\PgSQL\bin\pg_ctl.exe" stop -D "Y:\PortableProject\PostgreSQLPortable\Data\data"
The problem occurs on step 4. Even if I run it from computer A, I get the following error
psql: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "192.170.1.200" and accepting
TCP/IP connections on port 5432?
Am I doing it completely wrong? Is it even possible to reach my goal?
Is the server running on host "192.170.1.200" and accepting TCP/IP connections on port 5432?
That mean the server is running in 192.170.1.200, now you are executing from the server pc or from a different pc?
The pg_hba.conf is to list what other address / users are allow to access that sever.
So if you are access from the same pc you use
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
For external address you use something like
host all all 192.170.1.1/24 trust
This will allow access to pc with the following IP address range. IP Calculator
HostMin: 192.170.1.1
HostMax: 192.170.1.254

postgresql dblink_connect timeout

I am trying to use dblink to move data from one system to another. Both machines are RHEL 5.11, both running postgresql 9.2, both on the corp internal net with no firewall rules between them. I am working from my desktop vpn'ed into the corp internal net.
Call the two machines FROM and TO. The FROM machine has dblink installed as an extension, the TO machine does not. For both machines the user I am specifying has a pg_hba.conf host entry listing all for db's, 0.0.0.0/0 for address, and trust.
Using pgadmin3, I can connect to both machines from my desktop, see/add/modify databases on both. I think this rules out both trivial connection issues and permissions as potential sources of the problem.
in a pgadmin query window for the FROM machine, I execute this:
SELECT dblink_connect('AAA','host=TO dbname=XXX user=postgres password=ZZZ');
-OR-
SELECT dblink_connect('host=TO dbname=XXX user=postgres password=ZZZ');
-OR-
Either variety above entered at a psql command line on the FROM machine.
Results in this message delivered in the messages-pane or to the command line:
----- ERROR: could not establish connection DETAIL: could not connect to server: Connection timed out Is the server running on host
"TO" (AAA.BBB.CCC.DDD) and accepting TCP/IP connections on port 5432?
********** Error **********
ERROR: could not establish connection SQL state: 08001
Detail: could not connect to server: Connection timed out Is the
server running on host "TO" (AAA.BBB.CCC.DDD) and accepting TCP/IP
connections on port 5432?
Suggestions?
Update
-- tried replacing hostname "TO" with "localhost", same result.
-- however, dblink_connect('dbname_on_FROM'); works. so basic dblink functionality IS functionaing.
-- original problem remains unsolved as I want to ship data to a server on TO machine.
I am not sure if you were able to figure out the problem or not, but I am going to answer anyway. The "TO" machine's database might be running on a port different than 5432. You need to make sure the port your DB Server is running on and the port you specified in the "FROM" machine are the same.
If the port number is same, then there has to be a mistake in host, username or password when specifying these parameters in the "FROM" machine.

Postgres and Atlassian Jira: driver issue

I am trying to setup a server with centOS 32 bit to install Atlassian Jira on it.
I followed the official Atlassian installation guide at https://confluence.atlassian.com/display/JIRA/Installing+JIRA
Now I am running the Setup Wizard and I need to configure a PostgreSQL database. On my centOS, I installed version 8.4.20 via yum.
However, I am having a hard time setting Jira. Postgres is running and I can login via Linux console, but when I test the connection to the database, I get the following error:
Error connecting to database
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused
Also, this error appears when I type the full public IP address. If I insert localhost, I get this:
Error connecting to database
FATAL: Ident authentication failed for user "jiradbuser"
If I insert
http://<public ip>
I get the following:
Error connecting to database
No suitable driver found for jdbc:postgresql://http://<public ip>:5432/jiradb
However, I put my jdbc driver into /opt/atlassian/jira/lib and its name is postgresql-8.4-703.jdbc4.jar. Postgresql version is 8.4.20.
Where am I doing wrong?
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
By default, PostgreSQL listens only on the local loopback interface, so connecting to the public IP won't work. If you're connecting from localhost you don't need to anyway, just use localhost.
FATAL: Ident authentication failed for user "jiradbuser"
This is good, it shows that you're connecting to PostgreSQL successfully, then getting an authentication error when trying to log in.
Your PostgreSQL server install defaulted to ident authentication for TCP/IP connections, but the JIRA application isn't running under a unix user named "jiradbuser" so the connection is rejected. Change pg_hba.conf to use md5 instead of ident and set a password for the user. See the client authentication chapter in the docs, particularly, pg_hba.conf.
No suitable driver found for jdbc:postgresql://http://:5432/jiradb
I have no idea where you got the idea that that URL would work...
You want something like:
jdbc:postgresql://localhost:5432/jiradb
I had the same problem. I could solve it setting up the postgres driver .jar from maven repository to \target\jira\webapp\WEB-INF\lib\
Pretty late to the question here but thought I'd add a couple bits to help out the future, going backwards:
No suitable driver found for jdbc
A while ago Atlassian didn't distribute the PostGreSQL JDBC driver file with the JIRA releases. They have been doing this for a while now (I'd say since mid 2013) - regardless, the driver file belongs in the <jira-base>/lib directory unless you are doing a WAR install, in which case you shouldn't, and just put the driver file in the lib directory anyway
FATAL: Ident authentication failed for user "jiradbuser"
1. Listen on a socket if you need to - The best approach to this is to look at your JDBC driver URL - if it has an IP/hostname other than 127.x.x.x or 'localhost' you need to modify PostGreSQL to listen to a TCP port by modifying your postgresql.conf file to enable listening on ports. Just find the file, back it up, then open it and search for localhost, read the file comments and make the correct change. If you find yourself looking around in multiple locations in the file or changing more than a single word you are trying too hard - restore your backup and try again. Just remember to *stop* and *start* your postgres db cluster when you are done
2. enable the correct login METHOD in pg_hba.conf (same directory as the postgresql.conf file - on unix typically under /etc/postgresql/<version>/main/.) - this is difficult to writeup in brief but I'll try
1. backup the pg_hba.conf file - I ain't foolin, this is something you'll be happy with later - back the sucker up
2. edit the file
3. go to the bottom of the file - look for the last line like "# TYPE DATABASE USER ADDRESS METHOD"
4. comment out every line under this 'table heading' line
- the reason to do this is that the package maintainers often fall back to commenting here and so you'll have 2 commented out lines and then one line that isn't commented out - and you'll never notice it - it's easiest to just start off with commenting out the whole block of stuff so there isn't a single uncommented line in the file
- add a two lines for the postgres user to connect local and to a db socket unless your corporate security does not allow - something like this:
local all postgres 127.0.0.1/32 peer
host all postgres 127.0.0.1/32 trust
- add a line for your jiradbuser to connect to the newly created database via sockets with md5 encryption. md5 isn't the best - there are other options to google - if you use md5, it'd look something like this:
host jiraversiondb jiradbuser 127.0.0.1/32 md5
Then save the file, restart postgres cluster (with a stop and start, not with the 'restart' option), and test connecting from the command line.
How to test connections from the command line
If you are logged into a unix system with the postgres tools installed you should be able to mimic the connection attempt which the JIRA server will try to connect to the database. If you cannot connect to the new postgresql db from the command line it's a REAL GOOD chance that JIRA won't be able to either. Plus you'll get better error messages. So to do this just bring up a shell and enter (replacing variables where appropriate - things within the '<' and '>' characters) - all the values for these are in your head and the postgresql.conf file:
psql --port <port - default is 5434> --username=<db user name> --password --dbname=<database name>
Once you can connect from the command line it's a good bet JIRA will as well - no promises, but you'll be on sound footing.
...ahhh....now, that'll hopefully help someone...