@@ -29,7 +29,7 @@ std::size_t pg_result_t::affected_rows() const noexcept
2929std::atomic<std::uint32_t > pg_conn_t ::connection_id{0 };
3030
3131static PGconn *open_connection (connection_params_t const &connection_params,
32- std::uint32_t id)
32+ std::string_view context, std:: uint32_t id)
3333{
3434 std::vector<char const *> keywords;
3535 std::vector<char const *> values;
@@ -39,7 +39,7 @@ static PGconn *open_connection(connection_params_t const &connection_params,
3939 values.push_back (v.c_str ());
4040 }
4141
42- std::string const app_name{fmt::format (" osm2pgsql/C{}" , id)};
42+ std::string const app_name{fmt::format (" osm2pgsql.{} /C{}" , context , id)};
4343 keywords.push_back (" fallback_application_name" );
4444 values.push_back (app_name.c_str ());
4545
@@ -49,23 +49,25 @@ static PGconn *open_connection(connection_params_t const &connection_params,
4949 return PQconnectdbParams (keywords.data (), values.data (), 1 );
5050}
5151
52- pg_conn_t ::pg_conn_t (connection_params_t const &connection_params)
52+ pg_conn_t ::pg_conn_t (connection_params_t const &connection_params,
53+ std::string_view context)
5354: m_connection_id(connection_id.fetch_add(1 ))
5455{
55- m_conn.reset (open_connection (connection_params, m_connection_id));
56+ m_conn.reset (open_connection (connection_params, context, m_connection_id));
5657
5758 if (!m_conn) {
58- throw std::runtime_error{ " Connecting to database failed. " } ;
59+ throw fmt_error ( " Connecting to database failed (context={}). " , context) ;
5960 }
6061
6162 if (PQstatus (m_conn.get ()) != CONNECTION_OK) {
62- throw fmt_error (" Connecting to database failed: {}." , error_msg ());
63+ throw fmt_error (" Connecting to database failed (context={}): {}." ,
64+ context, error_msg ());
6365 }
6466
6567 if (get_logger ().log_sql ()) {
6668 auto const results = exec (" SELECT pg_backend_pid()" );
67- log_sql (" (C{}) New database connection (backend_pid={})" ,
68- m_connection_id, results.get (0 , 0 ));
69+ log_sql (" (C{}) New database connection (context={}, backend_pid={})" ,
70+ m_connection_id, context, results.get (0 , 0 ));
6971 }
7072
7173 // PostgreSQL sends notices in many different contexts which aren't that
0 commit comments