Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax locking requirements for collecting table stats #455

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions input/postgres/relation_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const relationStatsSQLInsertsSinceVacuumFieldDefault string = "0"

const relationStatsSQL = `
WITH locked_relids AS (
SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL
SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation'
),
locked_relids_with_parents AS (
SELECT DISTINCT inhparent relid FROM pg_catalog.pg_inherits WHERE inhrelid IN (SELECT relid FROM locked_relids)
Expand Down Expand Up @@ -117,7 +117,7 @@ SELECT relid,
`

const indexStatsSQL = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT s.indexrelid,
COALESCE(pg_catalog.pg_relation_size(s.indexrelid), 0) AS size_bytes,
COALESCE(s.idx_scan, 0),
Expand Down
10 changes: 5 additions & 5 deletions input/postgres/relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const relationsSQLOidField = "c.relhasoids AS relation_has_oids"
const relationsSQLpg12OidField = "false AS relation_has_oids"

const relationsSQL string = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT c.oid,
n.nspname AS schema_name,
c.relname AS table_name,
Expand Down Expand Up @@ -45,7 +45,7 @@ const relationsSQL string = `
AND ($1 = '' OR (n.nspname || '.' || c.relname) !~* $1)`

const columnsSQL string = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT c.oid,
a.attname AS name,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS data_type,
Expand Down Expand Up @@ -81,7 +81,7 @@ const columnsSQL string = `
FROM locked_relids`

const indicesSQL string = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT c.oid,
c2.oid,
i.indkey::text,
Expand Down Expand Up @@ -125,7 +125,7 @@ SELECT c.oid,
`

const constraintsSQL string = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT c.oid,
conname,
contype,
Expand Down Expand Up @@ -162,7 +162,7 @@ SELECT relid,
`

const viewDefinitionSQL string = `
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL)
WITH locked_relids AS (SELECT DISTINCT relation relid FROM pg_catalog.pg_locks WHERE mode = 'AccessExclusiveLock' AND relation IS NOT NULL AND locktype = 'relation')
SELECT c.oid,
pg_catalog.pg_get_viewdef(c.oid) AS view_definition,
false AS exclusively_locked
Expand Down