v.db.connect(1)
π v.db.connect π
okay bestie, welcome to v.db.connect(1) from the GRASS GIS User's Manual β this is the page that handles all the "who are you and where do you live" drama between your vector map and its attribute table. it prints connections, it sets connections, it's basically the group chat admin of your database links. let's get into it π
πΈ KEYWORDS πΈ
vector, attribute table, database, layer
β¨ SYNOPSIS β¨
v.db.connect
v.db.connect --help
v.db.connect [-pgcd] map=name [driver=name] [database=name]
[table=name] [key=name] [layer=string] [separator=character]
[--overwrite] [--help] [--verbose] [--quiet] [--ui]
π Flags π
-pβ prints literally every map connection parameter it can find, then dips. bye βοΈ-gβ same energy as-pbut in shell script style, then dips. the format is:layer[/layer name] table key database driver-cβ prints the types and names of the table columns for whatever layer you specified, then dips.-dβ deletes the connection for a certain layer (bestie, it does not delete the table itself, just the link ππ)--overwriteβ lets output files overwrite files that already exist--helpβ prints the usage summary--verboseβ verbose module output (it says the quiet part loud)--quietβ quiet module output (it says the loud part quiet)--uiβ forces the GUI dialog to launch
π¦ Parameters π¦
map=name[required] β the name of the vector map. or, plot twist, it can be the data source for direct OGR access. main character parameter, no cap.driver=nameβ name of the database driver.- Options:
dbf,mesql,mysql,odbc,ogr,pg,sqlite - Default:
sqlite
- Options:
database=nameβ name of the database.- Default:
$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
- Default:
table=nameβ name of the attribute table.key=nameβ name of the key column. it must refer to an integer column, ok? integer only, we don't make the rules.- Default:
cat
- Default:
layer=stringβ layer number or name.- Format:
layer number[/layer name] - Default:
1
- Format:
separator=characterβ the field separator for that shell script style output.- Special characters:
pipe,comma,space,tab,newline - Default:
pipe
- Special characters:
π DESCRIPTION π
v.db.connect prints or sets the database connection for a vector map. you can add or remove the link to an attribute table on a specific layer. that's the whole vibe. π«Ά
β NOTE β
the connection info β driver, database, table, key β is stored for each map, inside this file:
<database>/<project>/<mapset>/vector/<map>/dbln
if the database connection parameters were already set with db.connect, those get taken as the default values and you do not have to type them out every single time. slay, defaults. π
when you're printing the database connection (with the p or g flag), the parameter layer is ignored β like, fully ignored. all connections get printed to the output. periodt.
β οΈ Attention: removing a vector map will also delete all tables linked to it! π if you usev.db.connectto link further tables to your map, it is advisable to make a copy of those tables first, and connect the copied tables to the vector map instead (see alsov.overlay). protect your tables bestie, back them up first π
π§ EXAMPLE π§
Note: the default database backend setting is SQLite.
π₯ Print database connection
print all database connection parameters for a vector map:
v.db.connect -p map=roads
print the column types and names of the table linked to a vector map:
v.db.connect -c map=roads
π₯ Connect vector map to database (DBF driver)
connect a vector map to a DBF table, without or with variables.
using default DB connection:
v.db.connect map=vectormap table=table
using a hardcoded path to the DBF directory (not recommended, don't do this to yourself):
v.db.connect map=vectormap table=table \
database=/home/user/grassdata/spearfish60/PERMANENT/dbf
using a variable as the DBF directory definition β and heads up, single quotes must be used here:
v.db.connect map=vectormap table=table \
database=β$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/β
connect vector map layer 2 and key ID to the database with variables (note: if needed, single quotes must be used for the database parameter):
v.db.connect map=vectormap table=table layer=2 key=ID
π₯ Connect vector map to database (SQLite driver)
very similar to the DBF driver example above. π«
db.connect driver=sqlite database=β$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.dbβ
db.tables -p
v.db.connect map=vectormap table=table driver=sqlite \
database=β$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.dbβ
v.db.connect -p map=vectormap
π₯ Connect vector map to database (MySQL driver)
# note: connection which requires password
db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_database"
db.login user=joshua [password=xxx]
# ... or enter password interactively.
db.tables -p
# connect external table to layer 2:
v.db.connect map=my_map table=my_mysql_table key=baz layer=2
v.db.connect -p my_map
π₯ Connect vector map to database (PostgreSQL driver)
# note: connection without password being asked
v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \
database="host=myserver.itc.it,dbname=mydb,user=name" \
table=mytable key=id
π₯ Store geometry in GRASS but attributes in PostgreSQL
this example illustrates a mixed data storage setup, with the possibility to update attributes in an external PostgreSQL database:
# Check current settings for attribute storage:
db.connect -p
# Import table from PostgreSQL to new map
# (NOTE: output map name needs to be different from table name in
# case that GRASS is connected to PostgreSQL):
v.in.db driver=pg database="host=localhost,dbname=meteo" \
table=mytable x=lon y=lat key=cat out=mytable
v.db.connect map=mytable -p
# Cancel table connection between map and attribute table:
v.db.connect map=mytable -d
v.db.connect map=mytable -p
# Drop table which was replicated due to import:
db.tables -p
echo "DROP TABLE mytable" | db.execute
db.tables -p
# reconnect map to table in PostgreSQL:
v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \
table=mytable key=cat
# Now the geometry is stored in GRASS while the attributes are stored
# in PostgreSQL.
an alternative is to create a "view" of only ID, x, y [,z] columns and to use v.in.db on this view, then connect the original table to the geometry. this will be faster if the original table is very large. πβοΈπ¨
π₯ Store geometry in GRASS but attributes in PostGIS
this example illustrated a mixed data storage setup with the possibility to update attributes in an external PostGIS database:
# Check current settings for attribute storage:
db.connect -p
# Import table from PostGIS to new map
# (NOTE: output map name needs to be different from table name in
# case that GRASS is connected to PostGIS):
v.in.db driver=pg database="host=localhost,dbname=meteo" \
table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable
v.db.connect map=mytable -p
# Cancel table connection between map and attribute table:
v.db.connect map=mytable -d
v.db.connect map=mytable -p
# Drop table which was replicated due to import:
db.tables -p
echo "DROP TABLE mytable" | db.execute
db.tables -p
# reconnect map to table in PostGIS:
v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \
table=mytable key=cat
# Now the geometry is stored in GRASS while the attributes are stored
# in PostGIS.
π SEE ALSO π
db.connect, db.copy, db.tables, v.db.addtable, v.db.droptable, v.db.addcolumn, v.db.dropcolumn, v.external, v.in.db, v.overlay
GRASS SQL interface
π AUTHOR π
Radim Blazek, ITC-Irst, Trento, Italy
πΈ SOURCE CODE πΈ
available at: v.db.connect source code (history)
accessed: Saturday Jan 17 05:41:19 2026
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual
okay that's the whole page bestie, every flag, every default, every example, all of it π«Ά and for the cute sign-off: this lil manual page lives in GRASS 8.4.2, it's v.db.connect(1), it was accessed on Saturday Jan 17 05:41:19 2026, and it's Β© 2003-2025 GRASS Development Team from the GRASS GIS 8.4.2 Reference Manual. go connect something iconic πβ¨
π¦ 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