Connecting to postgres on OSX from Swift using PostgresClientKit
Hi, Wondered if anyone had experience connection to pg14.1 running on OSX using the swift library PostgresClientKit. I am having difficulties connecting and hopefully someone can put me on the right track. The following is the swift code I am using [Code] var config = ConnectionConfiguration() config.database = "mydb" config.user = "postgres" config.credential = .scramSHA256(password: "mypassword") config.port = "5432" config.ssl = true let connection = try PostgresClientKit.Connection(configuration: config) defer { connection.close() } [/Code] I have the following in my pg_hba.conf file: [Code] local all all scram-sha-256 [/Code] I can successfully connect using psql and/pgadmin, but when I try and connect in code I get the following error: [Code] [Connection-1 Severe] Unable to connect socket: Error Code: -9989(0x2705), Operation not permitted [/Code] Any suggestions? Thanks Howard Cole Selestial.com
Re: Connecting to postgres on OSX from Swift using PostgresClientKit
On 2022-07-31 23:42, Rob Sargent wrote: On 7/31/22 16:40, howardn...@selestial.com wrote: Hi, Wondered if anyone had experience connection to pg14.1 running on OSX using the swift library PostgresClientKit. I am having difficulties connecting and hopefully someone can put me on the right track. The following is the swift code I am using [Code] var config = ConnectionConfiguration() config.database = "mydb" config.user = "postgres" config.credential = .scramSHA256(password: "mypassword") config.port = "5432" config.ssl = true let connection = try PostgresClientKit.Connection(configuration: config) defer { connection.close() } [/Code] I have the following in my pg_hba.conf file: [Code] local all all scram-sha-256 [/Code] I can successfully connect using psql and/pgadmin, but when I try and connect in code I get the following error: [Code] [Connection-1 Severe] Unable to connect socket: Error Code: -9989(0x2705), Operation not permitted [/Code] Any suggestions? Thanks Howard Cole Selestial.com Maybe add config.host = "localhost"? Thanks, tried localhost, 127.0.0.1 and ::128. No joy
Re: Connecting to postgres on OSX from Swift using PostgresClientKit
On 2022-08-01 01:02, Tom Lane wrote: howardn...@selestial.com writes: On 2022-07-31 23:42, Rob Sargent wrote: On 7/31/22 16:40, howardn...@selestial.com wrote: I can successfully connect using psql and/pgadmin, but when I try and connect in code I get the following error: [Connection-1 Severe] Unable to connect socket: Error Code: -9989(0x2705), Operation not permitted Maybe add config.host = "localhost"? Thanks, tried localhost, 127.0.0.1 and ::128. No joy Don't know much about Swift, but it wouldn't surprise me if that code is running in some kind of sandbox that disallows IP connections by default. Swift/Xcode is new to me too! Also, does psql work when you say "psql -h localhost"? It's possible that your server isn't listening on localhost, or there's a firewall there. Your working connections could all be via Unix sockets, from what little you've said so far. regards, tom lane Using psql, i can successfully connect to localhost. In the postgresql.conf the listen address is *. The application was installed from the EDB installer; not sure about firewalls on sandboxes in this situation. Howard
Re: Connecting to postgres on OSX from Swift using PostgresClientKit
On 2022-08-01 01:04, Adrian Klaver wrote: On 7/31/22 16:53, howardn...@selestial.com wrote: On 2022-07-31 23:42, Rob Sargent wrote: On 7/31/22 16:40, howardn...@selestial.com wrote: Hi, Wondered if anyone had experience connection to pg14.1 running on OSX using the swift library PostgresClientKit. I am having difficulties connecting and hopefully someone can put me on the right track. Thanks Howard Cole Selestial.com Maybe add config.host = "localhost"? Thanks, tried localhost, 127.0.0.1 and ::128. No joy What error do you get in the above cases? Here is the error I get in the application. 2022-08-01T00:20:18.530Z Connection-1 finer] Created socket [2022-08-01T00:20:18.532Z Connection-1 fine] Opening connection to port 5432 on host localhost 2022-08-01 01:20:18.534308+0100 TestPostgres[10654:120173] dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:13 Err:-1 Errno:1 Operation not permitted 2022-08-01 01:20:18.535617+0100 TestPostgres[10654:120173] [si_destination_compare] socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL) failed: Operation not permitted 2022-08-01 01:20:18.535694+0100 TestPostgres[10654:120173] [si_destination_compare] socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL) failed: Operation not permitted [2022-08-01T00:20:18.537Z Connection-1 severe] Unable to connect socket: Error code: -9989(0x-2705), Operation not permitted [2022-08-01T00:20:18.537Z Connection-1 finer] Closing socket
Re: Connecting to postgres on OSX from Swift using PostgresClientKit
On 2022-08-01 01:04, Adrian Klaver wrote: On 7/31/22 16:53, howardn...@selestial.com wrote: On 2022-07-31 23:42, Rob Sargent wrote: On 7/31/22 16:40, howardn...@selestial.com wrote: Hi, Wondered if anyone had experience connection to pg14.1 running on OSX using the swift library PostgresClientKit. I am having difficulties connecting and hopefully someone can put me on the right track. Thanks Howard Cole Selestial.com Maybe add config.host = "localhost"? Thanks, tried localhost, 127.0.0.1 and ::128. No joy What error do you get in the above cases? When using 127.0.0.1... 2022-08-01T00:29:19.319Z Connection-1 finer] Created socket [2022-08-01T00:29:19.322Z Connection-1 fine] Opening connection to port 5432 on host 127.0.0.1 [2022-08-01T00:29:19.324Z Connection-1 severe] Unable to connect socket: Error code: -9989(0x-2705), Operation not permitted [2022-08-01T00:29:19.324Z Connection-1 finer] Closing socket
Re: Connecting to postgres on OSX from Swift using PostgresClientKit
On 2022-08-01 04:06, Adrian Klaver wrote: 2022-08-01T00:20:18.530Z Connection-1 finer] Created socket [2022-08-01T00:20:18.532Z Connection-1 fine] Opening connection to port 5432 on host localhost 2022-08-01 01:20:18.534308+0100 TestPostgres[10654:120173] dnssd_clientstub ConnectToServer: connect() failed A search on above error message found: https://github.com/firebase/firebase-ios-sdk/issues/3033 https://developer.apple.com/forums/thread/67792 https://github.com/emqx/CocoaMQTT/issues/202 all of which point to what Tom Lane mentioned, sandboxing. path:/var/run/mDNSResponder Socket:13 Err:-1 Errno:1 Operation not permitted 2022-08-01 01:20:18.535617+0100 TestPostgres[10654:120173] [si_destination_compare] socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL) failed: Operation not permitted 2022-08-01 01:20:18.535694+0100 TestPostgres[10654:120173] [si_destination_compare] socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL) failed: Operation not permitted [2022-08-01T00:20:18.537Z Connection-1 severe] Unable to connect socket: Error code: -9989(0x-2705), Operation not permitted [2022-08-01T00:20:18.537Z Connection-1 finer] Closing socket Hi Adrian, you & Tom were correct - it was sandbox settings (which was turned off??) in Xcode which caused the problems. In case anyone else has the problem, the steps I took to fix the problem in XCode 13.3 were as follows: 1. Go to the project explorer and select the project. 2. Select the Target under the list of Targets 3. Select the "Signing & Capabilities" Tab/Heading 4. Under the "App Sandbox" settings, select the "Outgoing connections (client)" checkbox. 5. Note - the "Enable App Sandbox" under Build Settings seems to have no effect! Apologies for not finding this myself - This was purely a MacOS / XCode problem - but many thanks to you all (Adrian, Tom, Rob) for proving yet again that Postgresql support is the best. Howard.
Could not load server certificate file "server.crt": No such file or directory.
Hi, Running 14.4.1 on Mac OSX on M1 and found that the postgres daemon had not started. It was running fine previously. When I ran the following command line: sudo -u postgres /Library/Postgresql/14/bin/postmaster -D /Library/Postgresql/14/data I get the following error: 2022-08-12 17:47:33.239 BST [896] FATAL: could not load server certificate file "server.crt": No such file or directory Not sure what I have done - but where do I find this file - and can I regenerate it easily? Thanks, Howard.
Re: Could not load server certificate file "server.crt": No such file or directory.
set ssl on. Check postgresql.conf to verify. If you don't want SSL on then set to off. If you want it on and need a certificate see: https://www.postgresql.org/docs/14/ssl-tcp.html#SSL-CERTIFICATE-CREATION You were right. Many thanks Howard.
Playing with pgcrypto
Hi all, I am trying out a few pgcrypto functions. I was expecting the final select statement to return the row I just inserted - Can anyone tell me what I am not understanding here? create table test (p1 bytea); insert into test (pgp_sym_encrypt('123', 'secret')); select * from test where pgp_sym_encrypt('123', 'secret') = p1; Thanks. Howard
Re: Playing with pgcrypto
pgp_sym_encrypt uses a random salt each time, so you cannot compare the output to p1 like you would do with crypt to verify a given plaintext. Instead, use pgp_sym_decrypt with p1 as input to get the plaintext. -- Erik Ah! That makes sense. Thanks Erik!