Skip to content

Commit ecfa06c

Browse files
authored
Replace cockroach encode-uri with convert-url in v26.2 (#23218)
1 parent b83d670 commit ecfa06c

4 files changed

Lines changed: 84 additions & 19 deletions

File tree

src/current/v26.2/connection-parameters.md

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,89 @@ SQL driver to determine whether these options are supported.
128128

129129
### Convert a URL for different drivers
130130

131-
The subcommand `cockroach convert-url` converts a connection URL, such as those printed out by [`cockroach start`]({% link {{ page.version.version }}/cockroach-start.md %}) or included in the online documentation, to the syntax recognized by various [client drivers]({% link {{ page.version.version }}/third-party-database-tools.md %}#drivers). For example:
131+
The subcommand `cockroach convert-url` converts a connection URL, such as those printed out by [`cockroach start`]({% link {{ page.version.version }}/cockroach-start.md %}) or included in the online documentation, to the syntax recognized by various [client drivers]({% link {{ page.version.version }}/third-party-database-tools.md %}#drivers).
132+
133+
{{site.data.alerts.callout_info}}
134+
The `cockroach encode-uri` command has been deprecated and merged into `cockroach convert-url`. Use `cockroach convert-url --format crdb` instead. The `encode-uri` command will be removed in a future release.
135+
{{site.data.alerts.end}}
136+
137+
#### Basic usage
138+
139+
By default, `convert-url` outputs the URL in multiple formats:
132140

133141
{% include_cached copy-clipboard.html %}
134142
~~~
135143
$ ./cockroach convert-url --url "postgres://foo/bar"
136144
~~~
137145

138146
~~~
139-
# Connection URL for libpq (C/C++), psycopg (Python), lib/pq & pgx (Go),node-postgres (JS)
140-
and most pq-compatible drivers:
141-
postgresql://root@foo:26257/bar
142-
# Connection DSN (Data Source Name) for Postgres drivers that accept DSNs - most drivers
143-
and also ODBC:
144-
database=bar user=root host=foo port=26257
147+
# Connection URL for libpq (C/C++), psycopg (Python), lib/pq & pgx (Go), node-postgres (JS) and most pq-compatible drivers:
148+
postgresql://root@foo:26257/bar
149+
150+
# Connection DSN (Data Source Name) for Postgres drivers that accept DSNs - most drivers and also ODBC:
151+
database=bar user=root host=foo port=26257
152+
145153
# Connection URL for JDBC (Java and JVM-based languages):
146-
jdbc:postgresql://foo:26257/bar?user=root
154+
jdbc:postgresql://foo:26257/bar?user=root
155+
156+
# Direct URL to CockroachDB:
157+
postgresql://root@foo:26257/bar
158+
~~~
159+
160+
#### Specify output format
161+
162+
Use the `--format` flag to output a specific format:
163+
164+
{% include_cached copy-clipboard.html %}
165+
~~~ shell
166+
cockroach convert-url --url "postgres://foo/bar" --format jdbc
167+
~~~
168+
169+
~~~
170+
jdbc:postgresql://foo:26257/bar?user=root
171+
~~~
172+
173+
Supported formats:
174+
175+
Format | Description
176+
-------|------------
177+
`pq` | Connection URL for libpq (C/C++), psycopg (Python), lib/pq & pgx (Go), node-postgres (JS), and most pq-compatible drivers
178+
`dsn` | Data Source Name for Postgres drivers that accept DSNs and ODBC
179+
`jdbc` | Connection URL for JDBC (Java and JVM-based languages)
180+
`crdb` | CockroachDB-specific URL format with inlined certificates for [Physical Cluster Replication]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}) and [Logical Data Replication]({% link {{ page.version.version }}/logical-data-replication-overview.md %})
181+
182+
#### Generate URLs for replication
183+
184+
To generate a connection URL for [Physical Cluster Replication]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}) or [Logical Data Replication]({% link {{ page.version.version }}/logical-data-replication-overview.md %}), use the `--format crdb` flag with the `--inline` flag to inline certificates directly into the URL:
185+
186+
{% include_cached copy-clipboard.html %}
187+
~~~ shell
188+
cockroach convert-url --url "postgresql://{user}:{password}@{node IP}:26257" --format crdb --ca-cert {path to CA certificate} --inline
147189
~~~
148190

191+
The `--inline` flag automatically sets `--format crdb`, so you can also use:
192+
193+
{% include_cached copy-clipboard.html %}
194+
~~~ shell
195+
cockroach convert-url --url "postgresql://{user}:{password}@{node IP}:26257" --ca-cert {path to CA certificate} --inline
196+
~~~
197+
198+
#### Additional flags
199+
200+
Flag | Description
201+
-----|------------
202+
`--url` | Connection URL to convert (required)
203+
`--format` | Output format: `pq`, `dsn`, `jdbc`, or `crdb`
204+
`--inline` | Inline certificates into the URL (automatically sets `--format crdb`)
205+
`--database` | Database name
206+
`--user` | Username
207+
`--password` | Password
208+
`--cluster` | Cluster name (sets `options=-ccluster=<name>`)
209+
`--certs-dir` | Path to certificates directory
210+
`--ca-cert` | Path to CA certificate
211+
`--cert` | Path to client certificate
212+
`--key` | Path to client private key
213+
149214
### Example URL for an insecure connection
150215

151216
The following URL is suitable to connect to a CockroachDB node using an insecure connection:

src/current/v26.2/failover-replication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ This section illustrates the steps to fail back to the original primary cluster
207207
ALTER VIRTUAL CLUSTER {cluster_a} STOP SERVICE;
208208
~~~
209209

210-
1. Open another terminal window and generate a connection string for **Cluster B** using [`cockroach encode-uri`]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}#step-3-manage-cluster-certificates-and-generate-connection-strings):
210+
1. Open another terminal window and generate a connection string for **Cluster B** using [`cockroach convert-url`]({% link {{ page.version.version }}/set-up-physical-cluster-replication.md %}#step-3-manage-cluster-certificates-and-generate-connection-strings):
211211

212212
{% include_cached copy-clipboard.html %}
213213
~~~ shell
214-
cockroach encode-uri {replication user}:{password}@{cluster B node IP or hostname}:26257 --ca-cert certs/ca.crt --inline
214+
cockroach convert-url --url "postgresql://{replication user}:{password}@{cluster B node IP or hostname}:26257" --format crdb --ca-cert certs/ca.crt --inline
215215
~~~
216216

217217
Copy the output ready for starting the PCR stream, which requires the connection string to **Cluster B**:

src/current/v26.2/set-up-logical-data-replication.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ To change the password later, refer to [`ALTER USER`]({% link {{ page.version.ve
181181
182182
In this step, you'll set up [external connection(s)]({% link {{ page.version.version }}/create-external-connection.md %}) to store the connection string for one or both clusters. Depending on how you manage certificates, you must ensure that all nodes between the clusters have access to the certificate of the other cluster.
183183

184-
You can use the `cockroach encode-uri` command to generate a connection string containing a cluster's certificate.
184+
You can use the `cockroach convert-url` command to generate a connection string containing a cluster's certificate.
185185
186-
1. On the **source** cluster in a new terminal window, generate a connection string, by passing the replication user, node IP, and port, along with the directory to the source cluster's CA certificate:
186+
1. On the **source** cluster in a new terminal window, generate a connection string by passing the connection URL for the replication user, along with the path to the source cluster's CA certificate:
187187

188188
{% include_cached copy-clipboard.html %}
189189
~~~ shell
190-
cockroach encode-uri postgresql://{user}:{password}@{node IP}:26257 --ca-cert {path to CA certificate} --inline
190+
cockroach convert-url --url "postgresql://{user}:{password}@{node IP}:26257" --format crdb --ca-cert {path to CA certificate} --inline
191191
~~~
192192

193193
The connection string output contains the source cluster's certificate:
@@ -224,7 +224,7 @@ Once the source cluster has made a connection to the destination cluster, the de
224224

225225
{% include_cached copy-clipboard.html %}
226226
~~~ shell
227-
cockroach encode-uri postgresql://{user}:{password}@{node IP}:26257 --ca-cert {path to CA certificate} --inline
227+
cockroach convert-url --url "postgresql://{user}:{password}@{node IP}:26257" --format crdb --ca-cert {path to CA certificate} --inline
228228
~~~
229229

230230
The connection string output contains the source cluster's certificate:

src/current/v26.2/set-up-physical-cluster-replication.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ To create certificates signed by an external certificate authority, refer to [Cr
253253

254254
At this point, the primary and standby clusters are both running. The next step creates a connection URI with the certifications needed to connect the two clusters. In most cases, we recommend ensuring that all nodes on the primary cluster have access to the certificate of the standby cluster, and vice versa. This ensures that PCR is able to parallelize the work.
255255

256-
Use the `cockroach encode-uri` command to generate a connection string containing a cluster's certificate for any [PCR statements]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}#manage-replication-in-the-sql-shell) that require a connection string. Pass the replication user, IP and port, along with the path to the certificate for the **primary cluster**, into the `encode-uri` command:
256+
Use the `cockroach convert-url` command to generate a connection string containing a cluster's certificate for any [PCR statements]({% link {{ page.version.version }}/physical-cluster-replication-overview.md %}#manage-replication-in-the-sql-shell) that require a connection string. Pass the connection URL for the replication user, along with the path to the certificate for the **primary cluster**, into the `convert-url` command:
257257
258258
{% include_cached copy-clipboard.html %}
259259
~~~ shell
260-
cockroach encode-uri {replication user}:{password}@{node IP or hostname}:26257 --ca-cert {path to certs directory}/certs/ca.crt --inline
260+
cockroach convert-url --url "postgresql://{replication user}:{password}@{node IP or hostname}:26257" --format crdb --ca-cert {path to certs directory}/certs/ca.crt --inline
261261
~~~
262262
263263
The connection string output contains the primary cluster's certificate:
@@ -404,7 +404,7 @@ Before you begin, you will need:
404404
(1 row)
405405
~~~
406406
407-
1. To create the replication job, you will need a connection string for the **primary cluster** containing its CA certificate. For steps to generate a connection string with `cockroach encode-uri`, refer to [Step 3. Manage cluster certificates and generate connection strings](#step-3-manage-cluster-certificates-and-generate-connection-strings).
407+
1. To create the replication job, you will need a connection string for the **primary cluster** containing its CA certificate. For steps to generate a connection string with `cockroach convert-url`, refer to [Step 3. Manage cluster certificates and generate connection strings](#step-3-manage-cluster-certificates-and-generate-connection-strings).
408408
409409
1. If you would like to run a test workload on your existing **primary cluster**, you can use [`cockroach workload`]({% link {{ page.version.version }}/cockroach-workload.md %}) like the following:
410410
@@ -468,8 +468,8 @@ Cluster | Virtual Cluster | Usage | URL and Parameters
468468
Primary | System | Set up a replication user and view running virtual clusters. Connect with [`cockroach sql`]({% link {{ page.version.version }}/cockroach-sql.md %}). | `"postgresql://root@{node IP or hostname}:{26257}?options=-ccluster=system&sslmode=verify-full"`<ul><li>`options=-ccluster=system`</li><li>`sslmode=verify-full`</li></ul>Use the `--certs-dir` flag to specify the path to your certificate.
469469
Primary | Main | Add and run a workload with [`cockroach workload`]({% link {{ page.version.version }}/cockroach-workload.md %}). | `"postgresql://root@{node IP or hostname}:{26257}?options=-ccluster=main&sslmode=verify-full&sslrootcert=certs/ca.crt&sslcert=certs/client.root.crt&sslkey=certs/client.root.key"`<br><br>{% include {{ page.version.version }}/connect/cockroach-workload-parameters.md %} As a result, for the example in this tutorial, you will need:<ul><li>`options=-ccluster={virtual_cluster_name}`</li><li>`sslmode=verify-full`</li><li>`sslrootcert={path}/certs/ca.crt`</li><li>`sslcert={path}/certs/client.root.crt`</li><li>`sslkey={path}/certs/client.root.key`</li></ul>
470470
Standby | System | Manage the replication stream. Connect with [`cockroach sql`]({% link {{ page.version.version }}/cockroach-sql.md %}). | `"postgresql://root@{node IP or hostname}:{26257}?options=-ccluster=system&sslmode=verify-full"`<ul><li>`options=-ccluster=system`</li><li>`sslmode=verify-full`</li></ul>Use the `--certs-dir` flag to specify the path to your certificate.
471-
Standby/Primary | System | Connect to the other cluster. | `"postgresql://{replication user}:{password}@{node IP or hostname}:{26257}/defaultdb?options=-ccluster%3Dsystem&sslinline=true&sslmode=verify-full&sslrootcert=-----BEGIN+CERTIFICATE-----{encoded_cert}-----END+CERTIFICATE-----%0A"`<br><br>Generate the connection string with [`cockroach encode-uri`](#step-3-manage-cluster-certificates-and-generate-connection-strings). Use the generated connection string in:<ul><li>`CREATE VIRTUAL CLUSTER` statements to [start the replication stream](#step-4-start-replication).</li><li>`ALTER VIRTUAL CLUSTER` statements to [fail back to the primary cluster]({% link {{ page.version.version }}/failover-replication.md %}#failback).</li></ul>
472-
Standby/Primary | System | Connect to the other cluster through its load balancer | `"postgresql://{replication user}:{password}@{node IP or hostname}:{26257}/defaultdb?options=-ccluster%3Dsystem&crdb_route=gateway&sslinline=true&sslmode=verify-full&sslrootcert=-----BEGIN+CERTIFICATE-----{encoded_cert}-----END+CERTIFICATE-----%0A"`<br><br>Generate the connection string with [`cockroach encode-uri`](#step-3-manage-cluster-certificates-and-generate-connection-strings) and manually add the `&crdb_route=gateway` parameter. Recommended only when nodes do not share the same network. Use the generated connection string in:<ul><li>`CREATE VIRTUAL CLUSTER` statements to [start the replication stream](#step-4-start-replication).</li><li>`ALTER VIRTUAL CLUSTER` statements to [fail back to the primary cluster]({% link {{ page.version.version }}/failover-replication.md %}#failback).</li></ul>
471+
Standby/Primary | System | Connect to the other cluster. | `"postgresql://{replication user}:{password}@{node IP or hostname}:{26257}/defaultdb?options=-ccluster%3Dsystem&sslinline=true&sslmode=verify-full&sslrootcert=-----BEGIN+CERTIFICATE-----{encoded_cert}-----END+CERTIFICATE-----%0A"`<br><br>Generate the connection string with [`cockroach convert-url`](#step-3-manage-cluster-certificates-and-generate-connection-strings). Use the generated connection string in:<ul><li>`CREATE VIRTUAL CLUSTER` statements to [start the replication stream](#step-4-start-replication).</li><li>`ALTER VIRTUAL CLUSTER` statements to [fail back to the primary cluster]({% link {{ page.version.version }}/failover-replication.md %}#failback).</li></ul>
472+
Standby/Primary | System | Connect to the other cluster through its load balancer | `"postgresql://{replication user}:{password}@{node IP or hostname}:{26257}/defaultdb?options=-ccluster%3Dsystem&crdb_route=gateway&sslinline=true&sslmode=verify-full&sslrootcert=-----BEGIN+CERTIFICATE-----{encoded_cert}-----END+CERTIFICATE-----%0A"`<br><br>Generate the connection string with [`cockroach convert-url`](#step-3-manage-cluster-certificates-and-generate-connection-strings) and manually add the `&crdb_route=gateway` parameter. Recommended only when nodes do not share the same network. Use the generated connection string in:<ul><li>`CREATE VIRTUAL CLUSTER` statements to [start the replication stream](#step-4-start-replication).</li><li>`ALTER VIRTUAL CLUSTER` statements to [fail back to the primary cluster]({% link {{ page.version.version }}/failover-replication.md %}#failback).</li></ul>
473473
Standby | Read only | Run read queries on the standby's replicating virtual cluster | `"postgresql://root@{node IP or hostname}:{26257}?options=-ccluster=main-readonly&sslmode=verify-full"`<ul><li>`options=-ccluster=main-readonly`</li><li>`sslmode=verify-full`</li></ul>Use the `--certs-dir` flag to specify the path to your certificate.
474474

475475
## What's next

0 commit comments

Comments
 (0)