You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/pypgstac.md
+92-1Lines changed: 92 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ There are two types of migrations:
57
57
-**Base migrations** install PgSTAC into a database with no current PgSTAC installation. These migrations follow the file pattern `"pgstac.[version].sql"`
58
58
-**Incremental migrations** are used to move PgSTAC from one version to the next. These migrations follow the file pattern `"pgstac.[version].[fromversion].sql"`
59
59
60
-
Migrations are stored in ```pypgstac/pypgstac/migration`s``` and are distributed with the pyPgSTAC package.
60
+
Migrations are stored in ```pypgstac/pypgstac/migrations``` and are distributed with the pyPgSTAC package.
61
61
62
62
### Running Migrations
63
63
pyPgSTAC has a utility for checking the version of an existing PgSTAC database and applying the appropriate migrations in the correct order. It can also be used to setup a database from scratch.
@@ -67,6 +67,97 @@ To create an initial PgSTAC database or bring an existing one up to date, check
67
67
pypgstac migrate
68
68
```
69
69
70
+
### Bootstrapping an Empty Database
71
+
72
+
When starting with an empty database, you have two options for initializing PgSTAC:
73
+
74
+
#### Option 1: Execute as Power User
75
+
76
+
This approach uses a database user with administrative privileges (such as 'postgres') to run the migration, which will automatically create all necessary extensions and roles:
77
+
78
+
```bash
79
+
# Set environment variables for database connection
80
+
export PGHOST=localhost
81
+
export PGPORT=5432
82
+
export PGDATABASE=yourdatabase
83
+
export PGUSER=postgres # A user with admin privileges
In production environments, you should assign these roles to your application database user rather than continuing to use the postgres user:
96
+
97
+
```sql
98
+
-- Grant appropriate roles to your application user
99
+
GRANT pgstac_read TO your_app_user;
100
+
GRANT pgstac_ingest TO your_app_user;
101
+
GRANT pgstac_admin TO your_app_user;
102
+
103
+
-- Set the search path for your application user
104
+
ALTERUSER your_app_user SET search_path TO pgstac, public;
105
+
```
106
+
107
+
#### Option 2: Create User with Initial Grants
108
+
109
+
If you don't have administrative privileges or prefer more control over the setup process, you can manually prepare the database before running migrations.
110
+
111
+
Connect to your database as an administrator and execute:
112
+
113
+
```sql
114
+
\c [database]
115
+
116
+
-- Create required extensions
117
+
CREATE EXTENSION IF NOT EXISTS postgis;
118
+
CREATE EXTENSION IF NOT EXISTS btree_gist;
119
+
CREATE EXTENSION IF NOT EXISTS unaccent;
120
+
121
+
-- Create required roles
122
+
CREATE ROLE pgstac_admin;
123
+
CREATE ROLE pgstac_read;
124
+
CREATE ROLE pgstac_ingest;
125
+
126
+
-- Grant appropriate permissions
127
+
ALTERDATABASE [database] OWNER TO [user];
128
+
ALTERUSER [user] SET search_path TO pgstac, public;
129
+
ALTERDATABASE [database] set search_path to pgstac, public;
130
+
GRANT CONNECT ON DATABASE [database] TO [user];
131
+
GRANT ALL PRIVILEGES ON TABLES TO [user];
132
+
GRANT ALL PRIVILEGES ON SEQUENCES TO [user];
133
+
GRANT pgstac_read TO [user] WITH ADMIN OPTION;
134
+
GRANT pgstac_ingest TO [user] WITH ADMIN OPTION;
135
+
GRANT pgstac_admin TO [user] WITH ADMIN OPTION;
136
+
```
137
+
138
+
Then run the migration as your non-admin user:
139
+
140
+
```bash
141
+
# Set environment variables for database connection
142
+
export PGHOST=localhost
143
+
export PGPORT=5432
144
+
export PGDATABASE=yourdatabase
145
+
export PGUSER=[user] # Your non-admin user
146
+
export PGPASSWORD=yourpassword
147
+
148
+
# Run the migration
149
+
pypgstac migrate
150
+
```
151
+
152
+
### Verifying Migration
153
+
154
+
To verify that PgSTAC was installed correctly:
155
+
156
+
```bash
157
+
# Check the PgSTAC version
158
+
pypgstac version
159
+
```
160
+
70
161
### Bulk Data Loading
71
162
A python utility is included which allows to load data from any source openable by smart-open using python in a memory efficient streaming manner using PostgreSQL copy. There are options for collections and items and can be used either as a command line or a library.
0 commit comments