You can extend PostgreSQL by bundling SQL objects into a package and using them as a unit. This page contains information about configuring the PostgreSQL extensions that Cloud SQL supports.
Use PostgreSQL extensions
You can install only the extensions that Cloud SQL supports. For more information, see PostgreSQL extensions supported by Cloud SQL .
Install an extension
Before using an extension, install it:
- In the psql tool, run the CREATE EXTENSION command.
Requirement for superuser privileges
In Cloud SQL, extensions can only be created by users that are part of the cloudsqlsuperuser
role. When you create a new PostgreSQL instance,
the default postgres
user is created for you (although you
must set the user's password). The default postgres
user is part of the cloudsqlsuperuser
role. For more information, see About PostgreSQL users
.
Inter-database connections
The target instances for connections must be in the same VPC network as the connecting instance.
For cluster instances, you can't choose the Require trusted client certificatesoption in the
Google Cloud console.
Additionally, to connect to databases within the same instance,
you cannot set host to
localhost or to 127.0.0.1
. Instead, you must use the IP address
shown for your instance in the Google Cloud console.
Request support for a new extension
You cannot create your own extensions in Cloud SQL.
To request support for an extension, click +1on the open issue or create a new issue. For a list of open Cloud SQL issues and information about creating new issues, see Search for or create issues and feature requests, by product .
PostgreSQL extensions supported by Cloud SQL
For information about using a specific extension, see the documentation link in one of the tables below.
Cloud SQL support for PostgreSQL extensions can be divided into these categories:
PostGIS
The PostGIS extension is supported for Cloud SQL for PostgreSQL for all major versions.
The following table contains the PostGIS extension versions for each Cloud SQL for PostgreSQL version:
Cloud SQL for PostgreSQL version | PostGIS extension |
---|---|
PostgreSQL 9.6 | 3.2.5 |
PostgreSQL 10 | 3.2.5 |
PostgreSQL 11 | 3.2.5 |
PostgreSQL 12 | 3.2.5 |
PostgreSQL 13 | 3.4.0 |
PostgreSQL 14 | 3.4.0 |
PostgreSQL 15 | 3.4.0 |
PostgreSQL 16 | 3.4.0 |
PostgreSQL 17 | 3.4.3 |
For a specific PostgreSQL major version, in the CREATE EXTENSION
command, you can
specify a PostGIS extension version by using the VERSION
clause.
The PostGIS extension includes the following:
-
postgis
-
postgis_raster
-
postgis_sfcgal
-
postgis_tiger_geocoder
-
postgis_topology
-
address_standardizer
-
address_standardizer_data_us
For more information, see PostGIS Installation .
Additionally, Cloud SQL for PostgreSQL includes version 3.3.0 of the pgRouting
extension, which extends PostGIS.
The pgRouting
extension enhances geospatial processing through network routing
and analysis.
You can upgrade PostGIS and its related extensions to their latest version manually. To learn more about upgrading your PostGIS extensions, see Upgrading PostGIS .
Data type extensions
Extension | Description |
btree_gin | Provides sample GIN operator classes that implement B-tree equivalent
behavior. PostgreSQL 9.6 uses version 1.0. PostgreSQL 10 uses version 1.2. All other versions use version 1.3. |
btree_gist | Provides GiST index operator classes that implement B-tree equivalent
behavior. PostgreSQL 9.6 uses version 1.2. PostgreSQL 10, 11, 12, and 13 use version 1.5. PostgreSQL 14 uses version 1.6. |
chkpass | Implements a data type chkpass
that is designed
for storing encrypted passwords.PostgreSQL 9.6 and 10 use version 1.0. Not supported for other versions. |
citext | Provides a case-insensitive character string type citext
.PostgreSQL 9.6 uses version 1.3. PostgreSQL 10 uses version 1.4. PostgreSQL 11 uses version 1.5. PostgreSQL 12, 13, and 14 use version 1.6. |
cube | Implements a data type cube
for representing multidimensional cubes.PostgreSQL 9.6 and 10 use version 1.2. PostgreSQL 11 uses version 1.3. PostgreSQL 12 and 13 use version 1.4. PostgreSQL 14 uses version 1.5. |
hstore | Implements the hstore
data type for storing sets of key/value pairs within a single PostgreSQL value.PostgreSQL 9.6 and 10 use version 1.4. PostgreSQL 11 uses version 1.5. PostgreSQL 12 uses version 1.6. PostgreSQL 13 uses version 1.7. PostgreSQL 14 uses version 1.8. |
isn | Provides data types for some international product numbering standards. PostgreSQL 9.6 and 10 use version 1.1. All other versions use version 1.2. |
ip4r | Provides data types for IPv4/v6 addresses, and address ranges, plus
index support. PostgreSQL uses version 2.4.2. |
ltree | Implements a data type ltree
for representing labels of data
stored in a hierarchical tree-like structure.PostgreSQL 9.6, 10, 11, and 12 use version 1.1. PostgreSQL 13 and 14 use version 1.2. |
lo | Support for managing Large Objects (also called LOs or BLOBs). Cloud SQL for PostgreSQL uses version 1.1. |
postgresql-hll | Introduces a new data type, hll
, which is a HyperLogLog
data structure. Also see postgresql-hll
in
this document.Cloud SQL for PostgreSQL uses version 2.16. |
prefix | Provides prefix-matching, plus index support. Cloud SQL for PostgreSQL uses version 1.2.0. |
Language extensions
Extension | Description |
plpgsql | A loadable procedural language for creating functions,
procedures and triggers. You also can use this language
for direct execution of code in DO blocks. Cloud SQL for PostgreSQL uses version 1.0. |
plv8 | Provides a procedural language for enabling JavaScript. Cloud SQL for PostgreSQL uses version 3.2.2, which in turn uses V8 JavaScript engine version 11.5. |
Miscellaneous extensions
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.2.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.1.
Cloud SQL for PostgreSQL uses version 1.1.
Cloud SQL for PostgreSQL uses version 1.2.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.1.
PostgreSQL 9.6, 10, 11, and 12 use version 1.2. PostgreSQL 13 uses version 1.3. PostgreSQL 14 uses version 1.5.
timestamp
field. You can use this to track the last time that a row in a database table is modified.Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.2.
PostgreSQL 9.6 and 10 use version 4.6.1. PostgreSQL 11 and later use version 4.7.0.
PostgreSQL 9.6 uses version 1.5. PostgreSQL 10 uses version 1.6. PostgreSQL 11 and 12 use version 1.7. PostgreSQL 13 and 14 use version 1.8.
- PostgreSQL 9.6 uses pgAudit, version 1.1.4 .
- PostgreSQL 10 uses pgAudit, version 1.2.3 .
- PostgreSQL 11 uses pgAudit, version 1.3.3 .
- PostgreSQL 12 uses pgAudit, version 1.4.2 .
- PostgreSQL 13 uses pgAudit, version 1.5.1 .
- PostgreSQL 14 uses pgAudit, version 1.6.1 .
Possible values to set for the audit log files for all versions of
pgAudit are READ
, WRITE
, FUNCTION
, ROLE
, DDL
, MISC
, and ALL
. For versions 1.4.2 through 1.6.1, you can also set the
value of MISC_SET
.
For more information about using this extension with Cloud SQL, see Audit for PostgreSQL using pgAudit .
Cloud SQL for PostgreSQL uses version 1.2.
PostgreSQL 9.6 uses version 1.2. PostgreSQL 10, 11, 12, 13, and 14 use version 1.3.
PostgreSQL versions 10 and later use version 1.6.0.
Cloud SQL for PostgreSQL uses version 1.3.
Cloud SQL for PostgreSQL uses version 2.4.3.
Cloud SQL for PostgreSQL uses version 1.3.1.
Cloud SQL for PostgreSQL uses version 1.2.
pgoutput
is a default plugin and is therefore supported on
all versions of Cloud SQL for PostgreSQL.PostgreSQL versions 13 and later support version 1.9.
PostgreSQL versions 14 and later support version 5.0.1 while PostgreSQL versions that are earlier than 14 support only up to version 4.7.4.
PostgreSQL 9.6 and 10 use version 1.1. PostgreSQL 11, 12, 13, and 14 use version 1.2.
Cloud SQL for PostgreSQL uses version 1.5.0.
Cloud SQL for PostgreSQL uses version 1.2.
PostgreSQL 9.6 uses version 1.4. All other versions use version 1.5.
Cloud SQL for PostgreSQL uses version 1.0.
PostgreSQL versions 11 and later use version 1.5.
PostgreSQL 9.6 uses version 1.4. PostgreSQL 10 and 11 use version 1.6. PostgreSQL 12 uses 1.7. PostgreSQL 13 uses 1.8. PostgreSQL 14 uses 1.9.
Cloud SQL for PostgreSQL uses version 1.3.0.
PostgreSQL 9.6 and 10 use version 1.3. PostgreSQL 11 and 12 use version 1.4. PostgreSQL 13 uses 1.5. PostgreSQL 14 uses version 1.6.
Creates and manages DB2 or Oracle-style global temporary tables in a PostgreSQL database.Cloud SQL for PostgreSQL uses version 3.0.
An open-source extension for storing and searching vector embeddings in PostgreSQL databases.PostgreSQL versions 12 and later support version 0.7.0 while PostgreSQL version 11 supports only up to version 0.5.1.
Cloud SQL for PostgreSQL uses version 1.2.
Cloud SQL for PostgreSQL uses version 2.11.0.
PostgreSQL 9.6, 10, 11, 12, and 13 use version 1.0. PostgreSQL 14 uses version 1.1.
Masks or replaces personally identifiable information (PII) or sensitive data from a PostgreSQL database. For more information, see the postgresql_anonymizer section.
Cloud SQL for PostgreSQL uses version 1.0.0.
Provides a HyperLogLog ( hll
) data structure that estimates the cardinality of a set.
Cloud SQL for PostgreSQL uses version 2.18.
Cloud SQL for PostgreSQL uses version 4.2.0.
Cloud SQL for PostgreSQL uses version 1.2.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.2.2.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.0.
Cloud SQL for PostgreSQL uses version 1.1.
Cloud SQL for PostgreSQL uses version 1.1.
More about some PostgreSQL extensions
This section describes more information about some of the supported PostgreSQL extensions in the tables above.
auto_explain
To begin using this extension on an instance, set the cloudsql.enable_auto_explain
flag to on
. For information about setting
flags, and to review the flags supported for this extension, see Configure database flags
.
To view logging data and events that are associated with the logs of the execution plans that this extension enables, see the Cloud Logging documentation.
Alternatively, for a user that has the cloudsqlsuperuser
role (only), you can
use the load
command to load this extension for one session.
dblink
From within a database session, you can use this extension to connect to PostgreSQL databases and execute queries.
Currently, this extension works for two Cloud SQL private IP instances within the same VPC network, or for cross databases within the same instance.
For additional information, see dblink in the PostgreSQL documentation.
Use dblink to connect with a password
To connect to databases, or to connect to the same instance as another user, you must specify a password. For example purposes (but not for production purposes), here is a code snippet:
SELECT * FROM dblink (
'dbname=name port=1234 host=host user=user password=password',
'select id, name from table' \
) AS t(id int, name text);
Alternatively, to only set up a connection, here is a code snippet for example purposes (not for production purposes):
SELECT dblink_connect('dbname=dblinktest user=postgres host=name_or_ip password=xxx');
Use dblink to connect without a password
To connect to the same instance as the same user, you can connect without a password. For example:
-
Set the following database flag to enable local connections without a password
cloudsql.allow_passwordless_local_connections
-
Connect without specifying a host, which implies connecting to the same instance. Here is an example:
SELECT * FROM dblink('dbname=finance user=alice', 'select income from revenue') AS revenue(income integer);
The result could be similar to the following:
income -------- 1000 (1 row)
To connect to databases within the same instance,
you cannot set host to localhost or to 127.0.0.1
. Instead,
you must use the IP address shown for your instance in the Google Cloud console.
Also see postgres_fdw and PL/Proxy in this document.
pageinspect
This extension inspects the contents of database pages at a low level. For more information, see pageinspect in the PostgreSQL documentation.
pg_bigm
This extension enables full-text search, and allows a two-gram (bigram) index for faster full-text search.
To begin using this extension on an instance, set the cloudsql.enable_pg_bigm
flag to on
. The following flags also are supported:
-
pg_bigm.enable_recheck
-
pg_bigm.gin_key_limit
-
pg_bigm.similarity_limit
For information about setting flags, and to review the flags supported for this extension, see Configure database flags .
pg_cron
To begin using pg_cron
on an
instance, set the cloudsql.enable_pg_cron
flag to on
. For information about
setting flags, and to review the flags supported for this extension, see Configure database flags
.
The jobs are configured as background workers, so you might need to
use standard PostgreSQL techniques
(such as the max_worker_processes
flag) to adjust the number of
those background workers.
For this extension, Cloud SQL supports the background worker mode, but not the libpq interface. Therefore, trust authentication directly involving this extension is not required.
pgfincore
This extension contains functions for managing pages in operating system disk cache memory from PostgreSQL. For more information, see the pgfincore documentation .
pg_freespacemap
This extension examines the free space map (FSM). For more information, see pg_freespacemap in the PostgreSQL documentation.
pg_hint_plan
To begin using this extension on an instance, set the cloudsql.enable_pg_hint_plan
flag to on
. For information about setting
flags, and to review the flags supported for this extension, see Configure database flags
.
Alternatively, for only a user with the cloudsqlsuperuser
role, you can
use the load
command to load this extension for one session.
pg_partman
This extension enables you to create and manage time-based and serial-based table partition sets.
In Cloud SQL, this extension doesn't include the background worker for automatic partition maintenance. Instead, you can use, for example, Cloud Scheduler to drive maintenance by calling maintenance functions at a regular interval.
pg_proctab
Here are the steps to use the pg_proctab extension to enable the pg_top utility:
- In the psql tool, run the CREATE EXTENSION command for pg_proctab.
- Download and run pg_top .
- When connecting to a Cloud SQL for PostgreSQL instance, add the
-r
option for connecting to a remote database, for getting metrics.
The following instance-wide metrics, which are included in the output, include usage by other supporting agents and services in the instance:
- Load average
- CPU states (% user, nice, system, idle, and iowait)
- Memory (used, free, and cached)
pg_repack
This extension enables you to remove bloat from tables and indexes. Optionally, you can use this extension to perform an online CLUSTER (order tables by cluster index). For more information, see the pg_repack documentation . Additionally, for use of this extension in Cloud SQL, a special procedure is needed for adding privileges to a user.
If a user outside of the cloudsqlsuperuser
role wants to use an extension,
you must grant the user cloudsqlsuperuser
privileges. For more information, in
this document, see Requirement for superuser privileges
.
The following example uses the GRANT
command to add the necessary privileges.
Example of adding privileges
For example purposes below, csuper1
is a cloudsqlsuperuser
and testdb
is a
database owned by testuser
. To create the pg_repack extension in testdb
,
initially run the following commands:
-
Connect to
testdb
as thecloudsqlsuperuser
:psql -U csuper1 -d testdb;
-
Grant the database owner, which is
testuser,
tocsuper1
:GRANT testuser TO csuper1;
-
Create the extension:
CREATE EXTENSION pg_repack;
-
Run the
pg_repack
command on a table, such ast1
intestdb
, ascsuper1
:pg_repack -h <hostname> -d testdb -U csuper1 -k -t t1
-
After the pg_repack job is completed, revoke the grant that you performed in step 2:
REVOKE testuser FROM csuper1;
The pg_repack
command might fail with the following error:
"ERROR: query failed: SSL SYSCALL error: EOF detected"
If that error occurs, try setting TCP keepalives to a smaller value and then run
the pg_repack
command. For more information, see Connections timeout (from Compute Engine)
.
pg_squeeze
This extension removes unused space from a table and optionally uses an index to sort tuples of the table. To begin using the extension on an instance, set the cloudsql.enable_pg_squeeze
flag to on
.
This extension also supports logical decoding by writing additional information to the write-ahead log (WAL). To enable this functionality for the extension, set the wal_level
configuration parameter to logical
or higher by setting the cloudsql.logical_decoding
flag to on
.
The extension requires a value to be set for the max_replication_slots
flag. If you
haven't specified a value for this flag, then set the value to 1
. Otherwise, add 1 to the value that's set for the flag.
For information about setting flags, and to review the flags supported for this extension, see Configure database flags .
pgtt
To begin using this extension on an instance, set the pgtt.enabled
flag to on
. For information about setting
flags, and to review the flags supported for this extension, see Configuring database flags
.
pg_visibility
This extension provides a way to examine the visibility map (VM) and the page-level visibility information of a table. For more information, see pg_visibility in the PostgreSQL documentation.
PL/Proxy
This extension is a procedural language handler that allows remote procedure calls among PostgreSQL databases, with optional sharding.
For more information, see the PL/Proxy documentation .
The target instances for connections must be in the same VPC network as the connecting instance. Additionally, you cannot choose, in the Google Cloud console, the Allow only SSL connectionsbutton for cluster instances.
To connect to databases within the same instance,
you cannot set host to localhost or to 127.0.0.1
. Instead,
you must use the IP address shown for your instance in the Google Cloud console.
Also see postgres_fdw and dblink in this document.
postgresql_anonymizer
To begin using this extension on an instance, set the cloudsql.enable_anon
flag to on
. For information about setting
flags, and to review the flags supported for this extension, see Configuring database flags
.
postgres_fdw
This extension allows tables from other ("foreign") PostgreSQL databases to be exposed as "foreign" tables in the current database. Those tables then are available for use, almost as if they were local tables. For more information, see postgres_fdw in the PostgreSQL documentation.
This extension works for two Cloud SQL private IP instances within the same VPC network, or for cross databases within the same instance.
To connect to databases within the same instance, you cannot set host to
localhost or to 127.0.0.1
. Instead, you must use the IP address
shown for your instance in the Google Cloud console.
Additionally, for an instance where foreign data is stored,
you can choose the Allow only SSL connectionsoption in the Google Cloud console.
You can't choose the Require trusted client certificatesoption.
Only the cloudsqlsuperuser
can be the owner
of a postgres_fdw
foreign data wrapper.
Also see PL/Proxy and dblink in this document.
postgresql-hll
This extension introduces a new data type, hll
, which is a HyperLogLog data
structure. For more information, see the postgresql-hll documentation
.