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 -p but 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
  • database=name β€” name of the database.
    • Default: $GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db
  • 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
  • layer=string β€” layer number or name.
    • Format: layer number[/layer name]
    • Default: 1
  • separator=character β€” the field separator for that shell script style output.
    • Special characters: pipe, comma, space, tab, newline
    • Default: pipe

🌈 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 use v.db.connect to 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 also v.overlay). protect your tables bestie, back them up first πŸ’–

🧚 EXAMPLE 🧚

Note: the default database backend setting is SQLite.

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