Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ And type `:dba <Enter>` in psql. (Or `\i /path/to/postgres_dba/start.psql` if yo
What to do if you need to connect to a remote Postgres server? Usually, Postgres is behind a firewall and/or doesn't listen to a public network interface. So you need to be able to connect to the server using SSH. If you can do it, then just create SSH tunnel (assuming that Postgres listens to default port 5432 on that server:

```bash
ssh -fNTML 9432:localhost:5432 sshusername@you-server.com
ssh -fNTML 9432:localhost:5432 sshusername@your-server.com
```

Then, just launch psql, connecting to port 9432 at localhost:
Expand Down Expand Up @@ -175,7 +175,7 @@ Once you added your queries, regenerate `start.psql` file:
/bin/bash ./init/generate.sh
```

Now your have the new `start.psql` and can use it as described above.
Now you have the new `start.psql` and can use it as described above.

‼️ If your new queries are good consider sharing them with public. The best way to do it is to open a Pull Request (https://help.github.com/articles/creating-a-pull-request/).

Expand Down
2 changes: 1 addition & 1 deletion matviews/refresh_all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- it might perform multiple iterations and eventually refreshes
-- all matviews (either all w/o data or absolutely all -- it's up to you).

-- set thos to TRUE here if you need ALL matviews to be refrehsed, not only those that already have been refreshed
-- set this to TRUE here if you need ALL matviews to be refreshed, not only those that already have been refreshed
set postgres_dba.refresh_matviews_with_data = FALSE;
-- alternatively, you can set 'postgres_dba.refresh_matviews_with_data_forced' to TRUE or FALSE in advance, outside of this script.

Expand Down
16 changes: 8 additions & 8 deletions sql/i2_redundant_indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Use it to see redundant indexes list

-- This query doesn't need any additional extensions to be installed
-- (except plpgsql), and doesn't create anything (like views or smth)
-- (except plpgsql), and doesn't create anything (like views or something)
-- -- so feel free to use it in your clouds (Heroku, AWS RDS, etc)

-- (Keep in mind, that on replicas, the whole picture of index usage
Expand Down Expand Up @@ -37,7 +37,7 @@ index_data as (
array_to_string(indclass, ', ') as opclasses
from pg_index i
join pg_class ci on ci.oid = i.indexrelid and ci.relkind = 'i'
where indisvalid = true and ci.relpages > 0 -- raise for a DD with a lot of indexes
where indisvalid = true and ci.relpages > 0 -- raise for a DB with a lot of indexes
), redundant_indexes as (
select
i2.indexrelid as index_id,
Expand All @@ -53,10 +53,10 @@ index_data as (
pg_get_indexdef(i2.indexrelid) index_def,
pg_relation_size(i2.indexrelid) index_size_bytes,
s.idx_scan as index_usage,
quote_ident(tnsp.nspname) as formated_schema_name,
coalesce(nullif(quote_ident(tnsp.nspname), 'public') || '.', '') || quote_ident(irel.relname) as formated_index_name,
quote_ident(trel.relname) AS formated_table_name,
coalesce(nullif(quote_ident(tnsp.nspname), 'public') || '.', '') || quote_ident(trel.relname) as formated_relation_name,
quote_ident(tnsp.nspname) as formatted_schema_name,
coalesce(nullif(quote_ident(tnsp.nspname), 'public') || '.', '') || quote_ident(irel.relname) as formatted_index_name,
quote_ident(trel.relname) AS formatted_table_name,
coalesce(nullif(quote_ident(tnsp.nspname), 'public') || '.', '') || quote_ident(trel.relname) as formatted_relation_name,
i2.opclasses
from
index_data as i1
Expand All @@ -80,9 +80,9 @@ index_data as (
and am1.amname = am2.amname -- same access type
and i1.columns like (i2.columns || '%') -- index 2 includes all columns from index 1
and i1.opclasses like (i2.opclasses || '%')
-- index expressions is same
-- index expressions are the same
and pg_get_expr(i1.indexprs, i1.indrelid) is not distinct from pg_get_expr(i2.indexprs, i2.indrelid)
-- index predicates is same
-- index predicates are the same
and pg_get_expr(i1.indpred, i1.indrelid) is not distinct from pg_get_expr(i2.indpred, i2.indrelid)
), redundant_indexes_fk as (
select
Expand Down
2 changes: 1 addition & 1 deletion sql/i4_invalid_indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- Use it to see invalid indexes list

-- This query doesn't need any additional extensions to be installed
-- (except plpgsql), and doesn't create anything (like views or smth)
-- (except plpgsql), and doesn't create anything (like views or something)
-- -- so feel free to use it in your clouds (Heroku, AWS RDS, etc)

-- (Keep in mind, that on replicas, the whole picture of index usage
Expand Down
6 changes: 3 additions & 3 deletions sql/i5_indexes_migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
-- you will drop it during the next cleanup routine procedure.

-- This query doesn't need any additional extensions to be installed
-- (except plpgsql), and doesn't create anything (like views or smth)
-- (except plpgsql), and doesn't create anything (like views or something)
-- -- so feel free to use it in your clouds (Heroku, AWS RDS, etc)

-- It also does't do anything except reading system catalogs and
-- It also doesn't do anything except reading system catalogs and
-- printing NOTICEs, so you can easily run it on your
-- production *master* database.
-- (Keep in mind, that on replicas, the whole picture of index usage
Expand Down Expand Up @@ -86,7 +86,7 @@ with unused as (
and am1.amname = am2.amname -- same access type
and (
i2.columns like (i1.columns || '%') -- index 2 includes all columns from index 1
or i1.columns = i2.columns -- index1 and index 2 includes same columns
or i1.columns = i2.columns -- index1 and index 2 include the same columns
)
and (
i2.opclasses like (i1.opclasses || '%')
Expand Down