Skip to content

Commit 2983165

Browse files
authored
Performance fixes (#57)
* add constraints to increase performance * fixes for multiple migration entries * remove unused code * get migrations / tests passing * make sure that existing migrations follow the unique key * make the incremental migration run partition_checks on all partitions * add docs for settings
1 parent b210b68 commit 2983165

File tree

16 files changed

+3590
-132
lines changed

16 files changed

+3590
-132
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ RUN \
4242
EXPOSE 5432
4343

4444
RUN mkdir -p /docker-entrypoint-initdb.d
45-
COPY ./sql /docker-entrypoint-initdb.d/
45+
COPY pgstac.sql /docker-entrypoint-initdb.d/
46+
COPY ./sql /docker-entrypoint-initdb.d/sql/
4647

4748
RUN mkdir -p /opt/src/pypgstac
4849

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ STAC Client that uses PGStac available in [STAC-FastAPI](https://github.com/stac
2222

2323
PGStac requires **Postgresql>=12**, **PostGIS>=3**, and **PG_Partman**. Best performance will be had using PostgreSQL>=13 and PostGIS>=3.1.
2424

25+
### PGStac Settings
26+
PGStac installs everything into the pgstac schema in the database. You will need to make sure that this schema is set up in the search_path for the database.
27+
28+
There are additional variables that control the settings used for calculating and displaying context (total row count) for a search.
29+
30+
Variables can be set either by passing them in via the connection options using your connection library or by setting them on the Role that is used to log in to the database.
31+
32+
```
33+
ALTER ROLE <username> SET SEARCH_PATH to pgstac, public;
34+
ALTER ROLE <username> SET pgstac.collection TO <'on','off','auto'>;
35+
ALTER ROLE <username> SET pgstac.context_estimated_count TO '<number of estimated rows when in auto mode that when an estimated count is less than will trigger a full count>';
36+
ALTER ROLE <username> SET pgstac.context_estimated_cost TO '<estimated query cost from explain when in auto mode that when an estimated cost is less than will trigger a full count>';
37+
ALTER ROLE <username> SET pgstac.context_stats_ttl TO '<an interval string ie "1 day" after which pgstac search will force recalculation of it's estimates>>';
38+
```
39+
2540
## PyPGStac
2641
PGStac includes a Python utility for bulk data loading and managing migrations.
2742

pypgstac/pypgstac/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""PyPGStac Version."""
2-
__version__ = "0.3.4"
2+
__version__ = "0.3.5"

pypgstac/pypgstac/migrate.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ async def get_version(conn: asyncpg.Connection) -> str:
112112
try:
113113
version = await conn.fetchval(
114114
"""
115-
SELECT version FROM pgstac.migrations
116-
ORDER BY datetime DESC LIMIT 1;
115+
SELECT version from pgstac.migrations
116+
order by datetime desc, version desc limit 1;
117117
"""
118118
)
119119
except asyncpg.exceptions.UndefinedTableError:
@@ -161,13 +161,6 @@ async def run_migration(
161161
migration_sql = get_sql(file)
162162
async with conn.transaction():
163163
await conn.execute(migration_sql)
164-
await conn.execute(
165-
"""
166-
INSERT INTO pgstac.migrations (version)
167-
VALUES ($1);
168-
""",
169-
toversion,
170-
)
171164

172165
newversion = await get_version(conn)
173166
await conn.close()

0 commit comments

Comments
 (0)