vercel-community / php

🐘 PHP Runtime for ▲ Vercel Serverless Functions (support 7.4-8.3)
https://php.vercel.app
MIT License
1.24k stars 284 forks source link

upgrade pdo_pgsql to support SNI #458

Open guoxiangke opened 1 year ago

guoxiangke commented 1 year ago

upgrade pdo_pgsql to support SNI

Hi, I use 8.1 & 8.2 and try to connect pgsql( provided by neon.tech) with laravel+vercel vercel-php@0.6.0 - PHP 8.2.x (https://example-php-8-2.vercel.app/) vercel-php@0.5.3 - PHP 8.1.x (https://example-php-8-1.vercel.app/)

But I met blow problems:

SQLSTATE[08006] [7] ERROR: Endpoint ID is not specified. Either please upgrade the postgres client library (libpq) for SNI support or pass the endpoint ID (first part of the domain name) as a parameter: '?options=endpoint%3D<endpoint-id>'. See more at https://neon.tech/sni
ERROR: connection is insecure (try using `sslmode=require`) (Connection: pgsql, SQL: select * from "users" where "email" = 
https://neon.tech/docs/connect/connectivity-issues

I tried config/database.config each options, not work 'sslmode' => 'verify-full',//prefer/require

I think we need update pdo_pgsql > 10.21
my local is pdo_pgsql 15.1 and works.

guoxiangke commented 1 year ago

thanks.

theaungmyatmoe commented 1 year ago

I am also facing that issue too, we have to update that in vercel php.

asispts commented 1 year ago

Related: https://github.com/vercel/storage/issues/120

f3l1x commented 1 year ago

Hi. Do you know which exactly libraries needs to be upgraded?

theaungmyatmoe commented 1 year ago

pgsql Liv I think so

coolymoon commented 9 months ago

Same here. Is there any way to upgrade the libpq?

The vercel-php@0.6.0 - PHP 8.2.x (https://example-php-8-2.vercel.app/) shows the version of libpq is 10.21, which is unsupported now.

The latest version is 16 and according to neon.tech (Vercel's Postgres provider), SNI support was added to the libpq in version 14, which was released in September 2021.

dbazhenov commented 9 months ago

I ran into a similar problem today. I make connection via pg_connect and to solve the problem I added options='endpoint=ep-shrill-disk-*****'

The connection worked successfully $connect_data = "host=ep-shrill-disk-.eu-central-1.aws.neon.tech port=5432 dbname=php-neon user=daniil.bazhenov password= sslmode=require options='endpoint=ep-shrill-disk-*****'";

$db_connect = pg_connect($connect_data);

deepakplay commented 9 months ago

@dbazhenov I was having the same issue in laravel vercel, How to do this "options='endpoint=ep-shrill-disk-*****'" in laravel, i tried but not working

braumye commented 8 months ago

If you're using Laravel, you can use this package https://github.com/braumye/laravel-vercel-postgres that add the endpoint to the options of the dsn and it worked for me.

Neon document: https://neon.tech/docs/connect/connection-errors#b-use-libpq-keyvalue-syntax-in-the-database-field

JIeJaitt commented 7 months ago

I encountered the same issue during deployment today and hope that Vercel can promptly upgrade pdo_pgsql to support SNI.

aungmoe32 commented 7 months ago

I faced same error today. I think it is because of pgsql lib.

DavidHGJ commented 7 months ago

hi i have a same error, i trying to use laravel with postgres, but when i access database to get data i have this error: "could not find driver (Connection: pgsql, SQL: select * from "users" where "email" = test@example.com limit 1)". Does anyone know how to solve this?

f3l1x commented 7 months ago

Hi, I will prepare PHP update with postgres14. I hope it will solve your troubles.

zone-connect commented 6 months ago

Hello, The official work-around that seems to work is to append the endpoint_ID with the password in the connection string like

DATABASE_URL=postgres://dbuser:<endpoint=<endpoint_id>>;<your_password>@ep-broad-snowflake-sdexc.il-central-1.aws.neon.tech/neondb?pgbouncer=true&connect_timeout=10

So basically, add this --> endpoint=<endpoint_id>; (including the comma)

Alternatively, if you are using database connection parameters, you can use the following

...
DB_PASSWORD='<endpoint=<endpoint_id>>;<your_password>' 

In our case, the endpoint ID is --> ep-broad-snowflake-sdexc (as seen in the connection URL above)

Hope this helps.

Yorften commented 2 months ago

@zone-connect Thenk you kind sir

ThiagoDOM commented 2 months ago

If you're using Laravel, you can use this package https://github.com/braumye/laravel-vercel-postgres that add the endpoint to the options of the dsn and it worked for me.

Neon document: https://neon.tech/docs/connect/connection-errors#b-use-libpq-keyvalue-syntax-in-the-database-field

Connect with success using this package, but now I have this error:

 INFO  Preparing database.  

  Creating migration table .............................................................................................................. 425ms DONE

   INFO  Running migrations.  

  2014_10_12_000000_create_users_table .................................................................................................. 704ms DONE
  2014_10_12_100000_create_password_reset_tokens_table .................................................................................. 844ms FAIL

   Illuminate\Database\QueryException 

  SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted, commands ignored until end of transaction block (Connection: pgsql, SQL: alter table "password_reset_tokens" add primary key ("email"))

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:822
    818▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    819▕                 );
    820▕             }
    821▕
  ➜ 822▕             throw new QueryException(
    823▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    824▕             );
    825▕         }
    826▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
      PDOException::("SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted, commands ignored until end of transaction block")

  2   vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
      PDOStatement::execute()