pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Connecting to postgres on OSX from Swift using PostgresClientKit
11+ messages / 5 participants
[nested] [flat]

* Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-07-31 22:40  howardnews@selestial.com
  0 siblings, 1 reply; 11+ messages in thread

From: howardnews@selestial.com @ 2022-07-31 22:40 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-07-31 22:42  Rob Sargent <robjsargent@gmail.com>
  parent: howardnews@selestial.com
  0 siblings, 1 reply; 11+ messages in thread

From: Rob Sargent @ 2022-07-31 22:42 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/31/22 16:40, howardnews@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"?

^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-07-31 23:53  howardnews@selestial.com
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 2 replies; 11+ messages in thread

From: howardnews@selestial.com @ 2022-07-31 23:53 UTC (permalink / raw)
  To: Rob Sargent <robjsargent@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On 2022-07-31 23:42, Rob Sargent wrote:
> On 7/31/22 16:40, howardnews@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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 00:02  Tom Lane <tgl@sss.pgh.pa.us>
  parent: howardnews@selestial.com
  1 sibling, 1 reply; 11+ messages in thread

From: Tom Lane @ 2022-08-01 00:02 UTC (permalink / raw)
  To: howardnews@selestial.com; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org

howardnews@selestial.com writes:
> On 2022-07-31 23:42, Rob Sargent wrote:
>> On 7/31/22 16:40, howardnews@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.

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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 00:04  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: howardnews@selestial.com
  1 sibling, 2 replies; 11+ messages in thread

From: Adrian Klaver @ 2022-08-01 00:04 UTC (permalink / raw)
  To: howardnews@selestial.com, Rob Sargent <robjsargent@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On 7/31/22 16:53, howardnews@selestial.com wrote:
> On 2022-07-31 23:42, Rob Sargent wrote:
>> On 7/31/22 16:40, howardnews@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?

> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 00:25  howardnews@selestial.com
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 11+ messages in thread

From: howardnews@selestial.com @ 2022-08-01 00:25 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org

On 2022-08-01 01:02, Tom Lane wrote:
> howardnews@selestial.com writes:
>> On 2022-07-31 23:42, Rob Sargent wrote:
>>> On 7/31/22 16:40, howardnews@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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 00:27  howardnews@selestial.com
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 1 reply; 11+ messages in thread

From: howardnews@selestial.com @ 2022-08-01 00:27 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org

On 2022-08-01 01:04, Adrian Klaver wrote:
> On 7/31/22 16:53, howardnews@selestial.com wrote:
>> On 2022-07-31 23:42, Rob Sargent wrote:
>>> On 7/31/22 16:40, howardnews@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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 00:30  howardnews@selestial.com
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 1 reply; 11+ messages in thread

From: howardnews@selestial.com @ 2022-08-01 00:30 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org

On 2022-08-01 01:04, Adrian Klaver wrote:
> On 7/31/22 16:53, howardnews@selestial.com wrote:
>> On 2022-07-31 23:42, Rob Sargent wrote:
>>> On 7/31/22 16:40, howardnews@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





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 02:38  Ron <ronljohnsonjr@gmail.com>
  parent: howardnews@selestial.com
  0 siblings, 0 replies; 11+ messages in thread

From: Ron @ 2022-08-01 02:38 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 7/31/22 19:30, howardnews@selestial.com wrote:
> On 2022-08-01 01:04, Adrian Klaver wrote:
>> On 7/31/22 16:53, howardnews@selestial.com wrote:
>>> On 2022-07-31 23:42, Rob Sargent wrote:
>>>> On 7/31/22 16:40, howardnews@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

This really looks like an error somewhere in the Mac OS networking stack.

What happens when you "telnet localhost 5432"?

-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 03:06  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: howardnews@selestial.com
  0 siblings, 1 reply; 11+ messages in thread

From: Adrian Klaver @ 2022-08-01 03:06 UTC (permalink / raw)
  To: howardnews@selestial.com; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org

On 7/31/22 17:27, howardnews@selestial.com wrote:
> On 2022-08-01 01:04, Adrian Klaver wrote:
>> On 7/31/22 16:53, howardnews@selestial.com wrote:
>>> On 2022-07-31 23:42, Rob Sargent 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


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: Connecting to postgres on OSX from Swift using PostgresClientKit
@ 2022-08-01 11:11  howardnews@selestial.com
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 11+ messages in thread

From: howardnews@selestial.com @ 2022-08-01 11:11 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Rob Sargent <robjsargent@gmail.com>; pgsql-general@lists.postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>

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.





^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2022-08-01 11:11 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31 22:40 Connecting to postgres on OSX from Swift using PostgresClientKit howardnews@selestial.com
2022-07-31 22:42 ` Rob Sargent <robjsargent@gmail.com>
2022-07-31 23:53   ` howardnews@selestial.com
2022-08-01 00:02     ` Tom Lane <tgl@sss.pgh.pa.us>
2022-08-01 00:25       ` howardnews@selestial.com
2022-08-01 00:04     ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-08-01 00:27       ` howardnews@selestial.com
2022-08-01 03:06         ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-08-01 11:11           ` howardnews@selestial.com
2022-08-01 00:30       ` howardnews@selestial.com
2022-08-01 02:38         ` Ron <ronljohnsonjr@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox