313 Commits

Author SHA1 Message Date
Jack Christensen
5044e8473a Add SCRAM authentication 2019-04-16 20:46:57 -05:00
Jack Christensen
038060776b Use LogLevel type instead of int for conn config
Technically, this is a change in the public interface. But it seems
extremely unlikely that it would cause any issues (and any that do
appear would be trivial to fix).

fixes #516
2019-03-23 11:22:47 -05:00
Ilya Sinelnikov
8fe19f698b Fix PreferSimpleProtocol overwrite
https://github.com/jackc/pgx/issues/495
2019-02-28 19:04:35 +03:00
Jack Christensen
6067cfab4f All Write errors are fatal
With TLS connections a Write timeout caused by a SetDeadline permanently
breaks the connection. However, the errors are reported as temporary. So
there is no way to determine if it really is recoverable. As these were
the only kind of Write error that was recovered all Write errors are now
fatal to the connection.

https://github.com/jackc/pgx/issues/494
https://github.com/jackc/pgx/issues/506
https://github.com/golang/go/issues/29971
2019-01-28 22:45:44 -06:00
Ilya Sivanev
a48ad29c16 Use more detailed error output of unknown field; 2019-01-21 17:51:35 +03:00
Jack Christensen
f25025a580
Merge pull request #486 from yobert/master
Fix two minor grammatical errors in source documentation
2018-12-01 10:38:57 -06:00
Joel Jensen
41b714110a Fix two minor grammatical errors in source documentation 2018-11-27 16:40:46 -07:00
James Hartig
6d336eccb1 Added LastStmtSent and use it to retry on errors if statement was not sent
Previously, a failed connection could be put back in a pool and when the
next query was attempted it would fail immediately trying to prepare the
query or reset the deadline. It wasn't clear if the Query or Exec call
could safely be retried since there was no way to know where it failed.

You can now call LastQuerySent and if it returns false then you're
guaranteed that the last call to Query(Ex)/Exec(Ex) didn't get far enough
to attempt to send the query. The call can be retried with a new
connection.

This is used in the stdlib to return a ErrBadConn if a network error
occurred and the statement was not attempted.

Fixes #427
2018-11-19 10:44:40 -05:00
Jack Christensen
a0d2ce5a0e
Merge pull request #477 from fastest963/cancel
Added option to customize query cancellation and wait for ready
2018-11-08 19:30:15 -06:00
James Hartig
527f404bbc Added option to customize query cancellation and wait for ready
CockroachDB doesn't support 80877102 and doesn't plan to, so instead allow
the user to customize the cancellation with their own function. In our
function, we call CANCEL QUERY with the query_id based on the LocalAddr().

The WaitForReady method can be used by a pool to not put a connection back
in the pool until it is finished cancelled and ready for a new query.
2018-11-05 20:28:59 -05:00
Jack Christensen
c10ee2b7bf
Merge pull request #473 from Mic92/unix-sockets
Add path query parameter to support unix sockets
2018-11-05 18:58:19 -06:00
Jörg Thalheim
3410ad9122
Add host query parameter to support unix sockets
Currently there is no way to specify unix sockets in the connection
url. This patch adds a `host` query parameter that allows to set the path.
2018-11-03 21:07:33 +00:00
Tejas Manohar
e2010c858c tls: stop sending ssl_renegotiation_limit in startup message
This addresses https://github.com/jackc/pgx/issues/321 with the
fix @jackc proposed there. Redshift users that need to connect
w/ SSL currently fork the library to delete this parameter, e.g.

8e0028d742

And, that's annoying to keep up-to-date :)
2018-10-29 21:50:09 -07:00
Murat Kabilov
d9f21d02a5 mind PreferSimpleProtocol parameter in the config Merge method 2018-07-24 16:03:26 +02:00
Jack Christensen
6556ef67cb Fix data race in domain handling 2018-04-07 14:26:26 -05:00
Jack Christensen
db7df79e10 Add domain support
fixes #407
2018-04-07 14:04:16 -05:00
Jack Christensen
a487caf45f Merge branch 'scheme-agnostic-uri' of https://github.com/sean-/pgx into sean--scheme-agnostic-uri 2018-02-03 11:43:46 -06:00
Jack Christensen
f911070f68 Add new SSL config to envvar parsing 2018-02-03 11:20:42 -06:00
Sean Chittenden
6cfb436397
Parse URI-encoded connection strings as URIs.
CockroachDB is frequently referenced as: `cockroachdb://` as its
scheme.  Be scheme name agnostic.
2018-02-02 16:19:58 -08:00
Sean Chittenden
6a4303120f
Only read in TLS certs when the key and cert are present. 2018-02-02 08:37:23 -08:00
Sean Chittenden
f0dc593c2f
Only initialize the CA if the path is not an empty string. 2018-02-02 08:24:41 -08:00
Sean Chittenden
8078930406
Add TLS arg parsing to ParseDSN().
Factor out the TLS cert handling and add it to `configTLS()` via a
`struct` argument.
2018-02-01 23:51:50 -08:00
Sean Chittenden
d7f24b91f4
Make ParseURI() compatible with lib/pq's TLS keywords.
Add support for:

- `sslrootcert`
- `sslcert`
- `sslkey`

All three arguments, like thir `gitub.com/lib/pq` counterparts,
are filesystem paths.
2018-02-01 22:58:14 -08:00
Sean Chittenden
4506a3e359
Gratuitously rename configSSL() to configTLS().
SSL is dead, Jim.
2018-02-01 15:07:59 -08:00
Jack Christensen
2c07b03087 Parse connect_timeout into Dial func
Instead of adding Timeout field which could conflict with custom Dial
func.
2018-01-13 18:02:13 -06:00
Jack Christensen
9281f057ae Merge branch 'timeout' of https://github.com/cyberdelia/pgx into cyberdelia-timeout 2018-01-13 17:31:22 -06:00
Jack Christensen
bd76a96882 Add ConnConfig.PreferSimpleProtocol
Allows configuring on a connection basis to prefer the simple protocol /
disable implicit prepared statements.

refs #331
2018-01-13 12:05:33 -06:00
Timothée Peignier
1bec450326
Handle timeout parameters 2017-12-16 19:18:33 -08:00
James Lawrence
393e9f4fd3 allow overriding connection info 2017-12-16 18:02:21 -05:00
Felix Geisendörfer
4dec986171 Fix CrateDB support (regression in ab9a1af)
See https://github.com/jackc/pgx/issues/320#issuecomment-338457176
2017-11-09 13:53:58 +01:00
Jack Christensen
ab9a1af65b Add support for array of enum
fixes #338
2017-10-17 20:31:11 -05:00
Felix Geisendörfer
52bec9bec5 Support CrateDB 2017-09-27 18:32:18 +02:00
Jack Christensen
fd7b776540 Merge pull request #323 from kelseyfrancis/namespace-oids
Prefix types in namespaces other than pg_catalog or public
2017-09-14 13:59:51 -05:00
Kelsey Francis
953e08df99 Prefix types in namespaces other than pg_catalog or public
It's possible to define a type (e.g., an enum) with the same name in two
different schemas. When initializing data types after connecting, types
defined within schemas other than pg_catalog or public should be
qualified with their schema name to disambiguate them and ensure all
types with the same base name get added to the map of OID to type.

Prior to this commit, the last type scanned would "win", and all others
with the same name would be missing from the ConnInfo type maps, which
would subsequently cause any PREPARE involving columns of those missing
types to return the error "unknown oid".
2017-09-11 11:29:42 -07:00
Jack Christensen
9eb21591ee Update sslmode docs 2017-09-09 11:05:39 -05:00
Johan Brandhorst
30fa7cc37f Skip certificate verification for sslmode "require"
This more appropriately aligns the behaviour of the library with
that advertised by the postgres documentation.

According to the table on the official documentation page
https://www.postgresql.org/docs/current/static/libpq-ssl.html,
the "require" mode should be used when:

"I want my data to be encrypted, and I accept the overhead. I trust that the network will make sure I always connect to the server I want."

This maps reasonably well to a TLS config that skips certificate verification.
2017-09-08 20:44:10 +01:00
Kelsey Francis
ea740fb316 Fix some invalid one round trip execs failing to return non-nil error
Prior to this commit, execEx() would write the one round trip exec to
the connection before first calling ensureConnectionReadyForQuery, which
ultimately caused any errors to be suppressed if the exec followed a
valid query, because the receive message processing would finish
successfully as soon as it received the ReadyForQuery that actually
belonged to the preceding query. So, the exec would never actually
receive the error message that it caused, leaving it to be incorrectly
received by the first subsequent query sent.
2017-08-28 18:51:35 -07:00
Jack Christensen
f65776f084 Fix typo 2017-08-25 13:31:50 -05:00
Jack Christensen
4d0f8f041b Fix pid logging
fixes #300
2017-08-12 17:43:54 -05:00
Jack Christensen
53b4280456 Automatically register enum types
fixes #287
2017-07-04 11:38:50 -05:00
Jack Christensen
8f4178b3d3 Use github.com/pkg/errors 2017-06-04 21:30:03 -05:00
Jack Christensen
3ea41e6972 Remove unused global error 2017-06-04 21:22:34 -05:00
Jack Christensen
fb90fb2729 Add notification response hook
refs #239
2017-06-04 21:18:26 -05:00
Jack Christensen
27ab289096 Use Go casing convention for OID 2017-06-03 11:53:49 -05:00
Jack Christensen
fe0af9b357 Happy-path batch query mode 2017-06-02 14:54:17 -05:00
Jack Christensen
dcf3ee2781 Fix sendPreparedQuery write error hang
If the Write call in sendPreparedQuery encountered a non-fatal error - which means it sent
no bytes. It still was marking the connection as not ready for query. That caused the next
call to hang.
2017-05-31 18:33:01 -05:00
Jack Christensen
90975ab5c2 Extract append message functions.
In general, pgproto3 types should be used. But these functions may be easier to
without incurring additional memory allocations.
2017-05-29 10:01:07 -05:00
Jack Christensen
4ee21a15de Use pgproto3 for startup message 2017-05-29 09:19:41 -05:00
Jack Christensen
dd5de3e49e Add single round-trip mode for ExecEx 2017-05-29 09:11:52 -05:00
Jack Christensen
749fdfe7d5 Resolve race on conn.Close/die
Use sync.Mutex instead of atomic operations for clarity.
2017-05-21 19:35:37 -05:00