sql: introduce and mandate explicit PostgreSQL connections#13552
Merged
benesch merged 2 commits intoMaterializeInc:mainfrom Jul 11, 2022
Merged
sql: introduce and mandate explicit PostgreSQL connections#13552benesch merged 2 commits intoMaterializeInc:mainfrom
benesch merged 2 commits intoMaterializeInc:mainfrom
Conversation
This was referenced Jul 11, 2022
54133d6 to
4c3782a
Compare
sploiselle
approved these changes
Jul 11, 2022
src/sql-parser/tests/testdata/ddl
Outdated
| CREATE SOURCE psychic FROM POSTGRES CONNECTION 'host=kanto user=ash password=teamrocket dbname=pokemon' PUBLICATION 'red' | ||
| => | ||
| CreateSource(CreateSourceStatement { name: UnresolvedObjectName([Ident("psychic")]), col_names: [], connection: Postgres { conn: "host=kanto user=ash password=teamrocket dbname=pokemon", publication: "red", details: None }, with_options: [], include_metadata: [], format: None, envelope: None, if_not_exists: false, materialized: false, key_constraint: None, remote: None }) | ||
| error: Expected FOR, found HOST |
Contributor
There was a problem hiding this comment.
Think this was meant to be a passing test
|
|
||
| > DROP SOURCE IF EXISTS mz_source CASCADE; | ||
| > DROP SECRET IF EXISTS pgpass CASCADE; | ||
| > DROP CONNECTION IF EXISTS pg CASCADE; |
Contributor
There was a problem hiding this comment.
Oh, derp--this shouldn't be necessary! Looks like we missed adding this diff:
diff --git a/src/testdrive/src/action/sql.rs b/src/testdrive/src/action/sql.rs
index b9b58f807..1e129c2c7 100644
--- a/src/testdrive/src/action/sql.rs
+++ b/src/testdrive/src/action/sql.rs
@@ -27,9 +27,9 @@ use mz_ore::retry::Retry;
use mz_ore::str::StrExt;
use mz_pgrepr::{Interval, Jsonb, Numeric};
use mz_sql_parser::ast::{
- CreateClusterReplicaStatement, CreateClusterStatement, CreateDatabaseStatement,
- CreateSchemaStatement, CreateSecretStatement, CreateSourceStatement, CreateTableStatement,
- CreateViewStatement, Raw, ReplicaDefinition, Statement, ViewDefinition,
+ CreateClusterReplicaStatement, CreateClusterStatement, CreateConnectionStatement,
+ CreateDatabaseStatement, CreateSchemaStatement, CreateSecretStatement, CreateSourceStatement,
+ CreateTableStatement, CreateViewStatement, Raw, ReplicaDefinition, Statement, ViewDefinition,
};
use crate::action::{Action, ControlFlow, State};
@@ -140,6 +140,13 @@ impl Action for SqlAction {
)
.await
}
+ Statement::CreateConnection(CreateConnectionStatement { name, .. }) => {
+ self.try_drop(
+ &mut state.pgclient,
+ &format!("DROP CONNECTION IF EXISTS {} CASCADE", name),
+ )
+ .await
+ }
_ => Ok(()),
}Line above should already be unnecessary.
Contributor
Author
There was a problem hiding this comment.
Ah, you're totally right that this was missed, but also this testdrive script runs with --no-reset so the logic there doesn't apply. So I applied your patch and left the code in question in place!
Use the same TLS types in CSR connections and Kafka connections, where appropriate. Also use a consistent naming scheme.
Introduce a new PostgreSQL connection type, as in...
CREATE CONNECTION pgconn FOR POSTGRES
HOST postgres,
DATABASE postgres,
USER postgres,
PASSWORD SECRET pgpass;
CREATE SOURCE pg FOR POSTGRES CONNECTION pgconn;
The connection options correspond to the old libpq connection parameters
in the obvious way.
As decided in #13374, this commit also removes the old syntax for
specifying PostgreSQL connection details inline in the `CREATE SOURCE`
statement; connection details *must* now be specified in `CREATE
CONNECTION`.
Touches #11504.
Touches #13374.
4c3782a to
746b58b
Compare
Contributor
Author
|
Thanks very much for the thorough review, @sploiselle! |
def-
added a commit
to def-/materialize
that referenced
this pull request
Mar 13, 2026
`X509::from_pem` only reads the first certificate from a PEM bundle, so if `ssl_root_cert` contains multiple CA certificates (e.g., root + intermediates or multiple roots), only the first is loaded into the trust store. This causes TLS verification to fail with "unknown ca" when the relevant trust anchor is not the first cert in the bundle, diverging from libpq behavior which accepts CA bundles. Fix by using `X509::stack_from_pem` (which parses all certs) and adding each to the cert store, mirroring the pattern already used in `pkcs12der_from_pem` in the same file. Bug introduced in PR MaterializeInc#13552 (commit fb6244a) which changed from file-based `set_ca_file()` to in-memory `add_cert(X509::from_pem())`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
def-
added a commit
that referenced
this pull request
Mar 20, 2026
`X509::from_pem` only reads the first certificate from a PEM bundle, so if `ssl_root_cert` contains multiple CA certificates (e.g., root + intermediates or multiple roots), only the first is loaded into the trust store. This causes TLS verification to fail with "unknown ca" when the relevant trust anchor is not the first cert in the bundle, diverging from libpq behavior which accepts CA bundles. Fix by using `X509::stack_from_pem` (which parses all certs) and adding each to the cert store, mirroring the pattern already used in `pkcs12der_from_pem` in the same file. Bug introduced in PR #13552 which changed from file-based `set_ca_file()` to in-memory `add_cert(X509::from_pem())`. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce a new PostgreSQL connection type, as in...
The connection options correspond to the old libpq connection parameters
in the obvious way.
As decided in https://github.com/MaterializeInc/database-issues/issues/3838, this commit also removes the old syntax for
specifying PostgreSQL connection details inline in the
CREATE SOURCEstatement; connection details must now be specified in
CREATE CONNECTION.Touches https://github.com/MaterializeInc/database-issues/issues/3354.
Touches https://github.com/MaterializeInc/database-issues/issues/3838.
Motivation
Testing
Release notes
This PR includes the following user-facing behavior changes: