Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/en_US/images/server_advanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/server_connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/server_general.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/server_parameters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/server_ssh_tunnel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/en_US/images/server_tags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/en_US/release_notes_9_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ New features
************

| `Issue #4194 <https://github.com/pgadmin-org/pgadmin4/issues/4194>`_ - Added support to automatically open a file after it is downloaded in the desktop mode.
| `Issue #4503 <https://github.com/pgadmin-org/pgadmin4/issues/4503>`_ - Added support for post-connection SQL execution, which will be run automatically on each connection made to any database of the server.
| `Issue #5871 <https://github.com/pgadmin-org/pgadmin4/issues/5871>`_ - Add support for restoring plain SQL database dumps.
| `Issue #8034 <https://github.com/pgadmin-org/pgadmin4/issues/8034>`_ - Added support for creating Directory nodes in EPAS.
| `Issue #8449 <https://github.com/pgadmin-org/pgadmin4/issues/8449>`_ - Change icon buttons to show tooltip even when disabled.
Expand All @@ -34,6 +35,7 @@ Bug fixes
*********

| `Issue #8006 <https://github.com/pgadmin-org/pgadmin4/issues/8006>`_ - Removed the pre-install script from the Red Hat build function as it was causing a No such file or directory warning during the update.
| `Issue #8316 <https://github.com/pgadmin-org/pgadmin4/issues/8316>`_ - Ensure that modal dialogs are not triggered more than once to avoid duplicates.
| `Issue #8355 <https://github.com/pgadmin-org/pgadmin4/issues/8355>`_ - Change session files garbage collection strategy.
| `Issue #8437 <https://github.com/pgadmin-org/pgadmin4/issues/8437>`_ - Fixed an issue where the PSQL terminal displays keyname for non alphanumeric keys.
| `Issue #8462 <https://github.com/pgadmin-org/pgadmin4/issues/8462>`_ - Fixed an issue where geometries in the geometry viewer will render partially when the container was resized.
Expand Down
25 changes: 17 additions & 8 deletions docs/en_US/server_dialog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ Use the fields in the *Advanced* tab to configure a connection:

.. note:: The Password exec option is only supported when pgAdmin is run in desktop mode.

* Click the *Save* button to save your work.
* Click the *Close* button to exit without saving your work.
* Click the *Reset* button to return the values specified on the Server dialog
to their original condition.
Click the *Post Connection SQL* tab to continue.

.. toctree::
.. image:: images/server_post_connection_sql.png
:alt: Server dialog post connection sql tab
:align: center

clear_saved_passwords
* Use the *Post Connection SQL* field to write the SQL queries that will be
executed in autocommit mode for each connection made to any database on this server.


Click the *Tags* tab to continue.
Expand All @@ -245,6 +245,15 @@ Use the table in the *Tags* tab to add tags. The tags will be shown on the right
a server node label in the object explorer tree.

Click on the *+* button to add a new tag. Some of the parameters are:
* *Text* field to specify the tag name.
* *Color* field to select the accent color of the tag.


* Click the *Save* button to save your work.
* Click the *Close* button to exit without saving your work.
* Click the *Reset* button to return the values specified on the Server dialog
to their original condition.

.. toctree::

* *Text* field to specify the tag name.
* *Color* field to select the accent color of the tag.
clear_saved_passwords
33 changes: 33 additions & 0 deletions web/migrations/versions/e982c040d9b5_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2025, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################

"""

Revision ID: e982c040d9b5
Revises: 255e2842e4d7
Create Date: 2025-03-13 16:55:26.893395

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'e982c040d9b5'
down_revision = '255e2842e4d7'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('server', sa.Column('post_connection_sql', sa.String()))


def downgrade():
# pgAdmin only upgrades, downgrade not implemented.
pass
8 changes: 6 additions & 2 deletions web/pgadmin/browser/server_groups/servers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ def update(self, gid, sid):
'kerberos_conn': 'kerberos_conn',
'connection_params': 'connection_params',
'prepare_threshold': 'prepare_threshold',
'tags': 'tags'
'tags': 'tags',
'post_connection_sql': 'post_connection_sql'
}

disp_lbl = {
Expand Down Expand Up @@ -1053,6 +1054,7 @@ def properties(self, gid, sid):
'connection_string': display_connection_str,
'prepare_threshold': server.prepare_threshold,
'tags': tags,
'post_connection_sql': server.post_connection_sql,
}

return ajax_response(response)
Expand Down Expand Up @@ -1169,7 +1171,8 @@ def create(self, gid):
kerberos_conn=1 if data.get('kerberos_conn', False) else 0,
connection_params=connection_params,
prepare_threshold=data.get('prepare_threshold', None),
tags=data.get('tags', None)
tags=data.get('tags', None),
post_connection_sql=data.get('post_connection_sql', None)
)
db.session.add(server)
db.session.commit()
Expand Down Expand Up @@ -1585,6 +1588,7 @@ def connect(self, gid, sid, is_qt=False, server=None):

return make_json_response(
success=1,
errormsg=errmsg,
info=gettext("Server connected."),
data={
"sid": server.id,
Expand Down
7 changes: 7 additions & 0 deletions web/pgadmin/browser/server_groups/servers/static/js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,13 @@ define('pgadmin.node.server', [
To make sure all the menus for database is in the right state */
pgBrowser.enable_disable_menus(_item);

/* Below code is added to show the error message if
connection is successful, but there is an error to
run the post connection sql queries. */
if (res?.errormsg) {
pgAdmin.Browser.notifier.error(res.errormsg, null);
}

// We're not reconnecting
if (!_wasConnected) {
_tree.setInode(_item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ export default class ServerSchema extends BaseUISchema {
helpMessageMode: ['edit', 'create'],
helpMessage: gettext('If it is set to 0, every query is prepared the first time it is executed. If it is set to blank, prepared statements are disabled on the connection.')
},
{
id: 'post_connection_sql', label: gettext('Post Connection SQL'),
group: gettext('Post Connection SQL'),
mode: ['properties', 'edit', 'create'],
type: 'sql', isFullTab: true,
readonly: obj.isConnected,
helpMessage: gettext('Any query specified in the control below will be executed with autocommit mode enabled for each connection to any database on this server.'),
},
{
id: 'tags', label: gettext('Tags'),
type: 'collection', group: gettext('Tags'),
Expand Down
3 changes: 2 additions & 1 deletion web/pgadmin/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#
##########################################################################

SCHEMA_VERSION = 42
SCHEMA_VERSION = 43

##########################################################################
#
Expand Down Expand Up @@ -215,6 +215,7 @@ class Server(db.Model):
db.CheckConstraint('is_adhoc >= 0 AND is_adhoc <= 1'),
nullable=False, default=0
)
post_connection_sql = db.Column(db.String(), nullable=True)

def clone(self):
d = dict(self.__dict__)
Expand Down
16 changes: 15 additions & 1 deletion web/pgadmin/utils/driver/psycopg3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,11 @@ def _initialize(self, conn_id, **kwargs):

self._set_server_type_and_password(kwargs, manager)

ret_msg = self.execute_post_connection_sql(cur, manager)

manager.update_session()

return True, None
return True, ret_msg

def _set_user_info(self, cur, manager, **kwargs):
"""
Expand Down Expand Up @@ -669,6 +671,18 @@ def _set_server_type_and_password(self, kwargs, manager):
manager.server_cls = st
break

def execute_post_connection_sql(self, cur, manager):
# Execute post connection SQL if provided in the server dialog
errmsg = None
if manager.post_connection_sql and manager.post_connection_sql != '':
status = self._execute(cur, manager.post_connection_sql)
if status is not None:
errmsg = gettext(("Failed to execute the post connection SQL "
"with below error message:\n{msg}").format(
msg=status))
current_app.logger.error(errmsg)
return errmsg

def __cursor(self, server_cursor=False, scrollable=False):

if not get_crypt_key()[0] and config.SERVER_MODE:
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/utils/driver/psycopg3/server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def update(self, server):
self.connection_params = server.connection_params
self.create_connection_string(self.db, self.user)
self.prepare_threshold = server.prepare_threshold
self.post_connection_sql = server.post_connection_sql

for con in self.connections:
self.connections[con]._release()
Expand Down