Page 1 of 1

Postgresql on a network

Posted: Sat Feb 29, 2020 2:07 pm
by loulou2522
Hi all
I can't arrive to connect purebasic on a network where i install Postgresql
I put an instruct like that :
ouverture.l = OpenDatabase(#PB_Any, "host=xxx.xxx.x.xx/ port=5433 dbname=mandat", "postgres", "postgres",#PB_Database_PostgreSQL)
In pg_hba.conf i put
# IPv4 local connections:
host all all xxx.xxx.x.xx/32 md5
Can someone help me to solve that problem ?
Thanks

Re: Postgresql on a network

Posted: Sat Feb 29, 2020 2:59 pm
by spikey
The trailing / isn't part of the host address - is that just a typo in the posting or do you need to fix the source?
The default PostgreSQL port is 5432 not 5433. Did you change this on your server or have you typo'd that in the source code?
Do you really mean to have a 32 bit bitmask on the address in pg_hba.conf? You've blanked out the pertinent bits so I can't tell but if you aren't trying to connect to 127.0.0.1/localhost then you probably don't... If you're running a Class C LAN then you probably want a /24; unless you only want to be able to connect to your server from a single client machine of course...
Have you verified that the server is actually running/listening on that port?
Can you connect to the server with PSQL?

I'm sure a:

Code: Select all

Debug DatabaseError()
after OpenDatabase would be enlightening...

Re: Postgresql on a network

Posted: Sat Feb 29, 2020 3:23 pm
by loulou2522
spikey wrote:The trailing / isn't part of the host address - is that just a typo in the posting or do you need to fix the source?
The default PostgreSQL port is 5432 not 5433. Did you change this on your server or have you typo'd that in the source code?
Do you really mean to have a 32 bit bitmask on the address in pg_hba.conf? You've blanked out the pertinent bits so I can't tell but if you aren't trying to connect to 127.0.0.1/localhost then you probably don't... If you're running a Class C LAN then you probably want a /24; unless you only want to be able to connect to your server from a single client machine of course...
Have you verified that the server is actually running/listening on that port?
Can you connect to the server with PSQL?

I'm sure a:

Code: Select all

Debug DatabaseError()
after OpenDatabase would be enlightening...
It's actually a typo.
The synth I put is open.l = OpenDatabase (#PB_Any, "host = xxx.xxx.x.xx port = 5432 dbname = mandat","postgres'" "postgres", # PB_Database_PostgreSQL)
As for /24 or /32, I don't quite understand the meaning. Can you enlighten me
My need is to be able to connect several machines on the base station.
The network on which I want to access the base is a class B network.
When i use netstat the sytem resppond me that port 5432 is listening on IPV6 adress ::1

Re: Postgresql on a network

Posted: Sat Feb 29, 2020 6:09 pm
by spikey
An IP address is actually binary when it comes down to it (of course).

The bit mask is used when comparing incoming request source addresses to see if they're permitted. A bitwise and comparison is used.
/n is a shortcut nomenclature to say n out of 32 bits starting at the most significant bit end will be set in the mask.

A class C is the simplest example. A private class C network might be 192.168.1.x with node addresses issued between 1 and 254.
Node addresses 0 and 255 get reserved for other purposes in this instance.

This means that individual nodes will have addresses in this range in binary:

Code: Select all

11000000.10101000.00000001.00000001 to 
11000000.10101000.00000001.11111110
(Note that they will all have the first 24 bits in common - ignore the dots when counting).

Suppose you put this in the pg_hba.conf file:

Code: Select all

host all all 192.168.1.1/32 md5
The /32 says ALL 32 bits in the address must match for a source address to be ok. That is to say it must be identical.
In this case ONLY the client machine with the IP address 192.168.1.1 will be allowed to connect (by this rule anyway).

If you wanted any/all machines in the range 192.168.1.1 - 192.168.1.254 to connect you need to match the first 24 bits, because they have these in common, and ignore the last 8 bits.
The mask would need to look like this:

Code: Select all

11111111.11111111.11111111.00000000
This mask has the leftmost 24 bits set to 1, so the entry for this particular network would be:

Code: Select all

host all all 192.168.1.0/24 md5
Your case is a little different because it's class B not C.
Assuming a private class B network 172.16.0.0 with no additional subnetting and you want all nodes to be able to access the server.
Node addresses 172.16.0.1 - 172.16.255.254 will be valid and 172.16.0.0 and 172.16.255.255 will be reserved.
The common part of the addresses will be the first 16 bits and the last 16 should be ignored.

That is to say the mask would need to look like this:

Code: Select all

11111111.11111111.00000000.00000000
The entry for this network would be:

Code: Select all

host all all 172.16.0.0/16 md5

Re: Postgresql on a network

Posted: Fri Mar 06, 2020 11:53 am
by flaith
loulou2522 wrote:
ouverture.l = OpenDatabase(#PB_Any, "host=xxx.xxx.x.xx/ port=5433 dbname=mandat", "postgres", "postgres",#PB_Database_PostgreSQL)
Hi

instead of using "host=", did you try with "hostaddr"
ouverture.l = OpenDatabase(#PB_Any, "hostaddr=xxx.xxx.x.xx port=5433 dbname=mandat", "postgres", "postgres",#PB_Database_PostgreSQL)
For the pg_hba.conf :
# IPv4 local connections:
#host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5