grass-pg(1)
π grass-pg β PostgreSQL DATABASE DRIVER π
okay bestie, gather round, because this one is literally the moment GRASS GIS links arms with PostgreSQL and stores all your vector attributes on a whole actual database server. this is grass-pg(1) from the GRASS GIS User's Manual and it's giving main character energy fr fr π¦
β¨ PostgreSQL DATABASE DRIVER β¨
PostgreSQL database driver = the thing that lets GRASS keep your vector attributes inside a PostgreSQL server instead of just chillin' in a local file. iconic behavior, no cap. π
πΈ Creating a PostgreSQL database πΈ
a brand new database gets born via createdb. that's it, that's the vibe β go peek at the PostgreSQL manual if you want the deets, because it's all theirs. π
π Connecting GRASS to PostgreSQL π
here's the glow-up sequence, watch closely:
# example for connecting to a PostgreSQL server:
db.connect driver=pg database=mydb
db.login user=myname password=secret host=myserver.osgeo.org # port=5432
db.connect -p
db.tables -p
that's connect β login β vibe check the connection β vibe check the tables. we love a little pipeline. β¨
π Username and password π
straight from the PostgreSQL manual, bestie, quoting it so you don't have to go hunting:
The file.pgpassin a user's home directory can contain passwords to be used if the connection requires a password (and no password has been specified otherwise). On Microsoft Windows the file is named%APPDATA%\postgresql\pgpass.conf(where%APPDATA%refers to the Application Data subdirectory in the user's profile). Alternatively, a password file can be specified using the connection parameterpassfileor the environment variablePGPASSFILE. This file should contain lines of the following format:
hostname:port:database:username:password
put that line in a file, protect it, and your password never has to show up in your shell history again. we stan a discreet queen. π€«π
π§ Supported SQL commands π§
All SQL commands that PostgreSQL supports. all of them. the whole menu. π
β οΈ but bestie, listen: it is not possible to use C-like escapes (the backslash ones like \n etc) inside the SQL syntax. so don't try it, she will not eat. π
π Operators available in conditions π
All SQL operators that PostgreSQL supports. yes queen, every single one. π
π Adding an unique ID column π
import vector modules need an unique ID column, and you can manifest one in a PostgreSQL table like this:
db.execute sql="ALTER TABLE mytable ADD ID integer"
db.execute sql="CREATE SEQUENCE mytable_seq"
db.execute sql="UPDATE mytable SET ID = nextval(βmytable_seqβ)"
db.execute sql="DROP SEQUENCE mytable_seq"
add the column, spin up a sequence, fill it in, then yeet the sequence. clean. β¨
π Attribute import into PostgreSQL π
CSV import into PostgreSQL goes a little something like:
\h copy
COPY t1 FROM βfilenameβ USING DELIMITERS β,β;
(\h copy is you asking for help on copy, because we always ask for help. growth mindset. π±)
π¦ Geometry import from PostgreSQL table into GRASS π¦
v.in.db creates a new vector (points) map from a database table that's holding coordinates. see here for examples. π
πΈ PostGIS: PostgreSQL with vector geometry πΈ
PostGIS β it adds geographic object support to PostgreSQL. it's PostgreSQL but with β¨spatial feelingsβ¨.
πΊοΈ Example: Import from PostGIS πΊοΈ
in an existing PostGIS database, create the following table:
CREATE TABLE test
(
id serial NOT NULL,
mytime timestamp DEFAULT now(),
text varchar,
wkb_geometry geometry,
CONSTRAINT test_pkey PRIMARY KEY (id)
) WITHOUT OIDS;
# insert value
INSERT INTO test (text, wkb_geometry)
VALUES (βNameβ,geometryFromText(βPOLYGON((600000 200000,650000
200000,650000 250000,600000 250000,600000 200000))β,-1));
# register geometry column
select AddGeometryColumn (βpostgisβ, βtestβ, βgeometryβ, -1, βGEOMETRYβ, 2);
then GRASS can import this PostGIS polygon map like so:
v.in.ogr input="PG:host=localhost dbname=postgis user=neteler" layer=test \
output=test type=boundary,centroid
v.db.select test
v.info -t test
import it, select from it, get the info on it. the full circle moment. π«Ά
π Geometry Converters π
- PostGIS with
shp2pgsql:
shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql
e00pg: E00 to PostGIS filter, see alsov.in.e00.- GDAL/OGR
ogrinfoandogr2ogr: GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS.
ogr2ogr -f "PostgreSQL" shapefile ??
π SEE ALSO π
db.connect,db.execute- Database management in GRASS GIS
- Help pages for database modules
- SQL support in GRASS GIS
π REFERENCES π
- PostgreSQL web site
- pgAdmin graphical user interface
- GDAL/OGR PostgreSQL driver documentation
πΎ SOURCE CODE πΎ
Available at: PostgreSQL DATABASE DRIVER source code (history)
Accessed: Saturday Jan 17 05:40:32 2026
Main index | Topics index | Keywords index | Graphical index | Full index
and that's the whole page bestie, you ate that π β¨
Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual β and yes this manual is literally labeled GRASS 8.4.2 at the bottom, grass-pg(1), periodt. πππ¦πΈπ
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms