Перейти к содержимому

Как подключить postgresql к pycharm

  • автор:

Как подключить postgresql к pycharm

Vignesh Babu B R B

Use ⇧⇧ (macOS) / Shift+Shift (Windows/Linux), to bring up the Search Everywhere dialog. You can now search for Database to open the Database tool window which helps you to connect to multiple databases and DDL data sources.

You click on the + (New) button. Select Data Source then Postgres as the data source type. Customize the name of the data source, connection details, then click on the Test link to ensure everything is ok.

Once everything is done, a Console tab will appear and you can now query the database from the IDE. You can also explore it from the Database tool window, and select which parts to hide or show from it.

Note: You may need to download a database driver for the IDE first. If you see a Download driver link, you’ll need to click on that before you can connect to the database.

Alternately, you can open Database tool window from the Sidebar of the IDE:

Open Database Tool Window from Sidebar

Connection to a database

This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in PyCharm by default. If the relevant features aren’t available, make sure that you didn’t disable the plugin.

The Database Tools and SQL plugin is available only in PyCharm Professional.

  1. Press Control+Alt+S to open the IDE settings and then select Plugins .
  2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

This topic gives you an overview of how the connection to a database works in PyCharm. For more information about features and concepts, refer to the dedicated topics.

Data source

To connect to a database, PyCharm requires connection details (for example, host, port, password, SSH configuration settings, and so on). For every database, the connection details are stored in a dedicated connection configuration — data source .

Below is an example of the PostgreSQL data source settings in the Data Sources and Drivers dialog ( Shift+Enter ).

Data source with connection details for a PostgreSQL database

Session

For a data source, connections to the database are established in special wrappers — sessions . Each session is a wrapper over a single connection, and it stores the connection’s information (for example, whether it is active or not, transaction control mode, and other settings).

Sessions can have clients — files, whose queries are sent via the connection that the session holds. Data editor can also be a client for a session.

Depending on the way you create a new session, it can be connected either automatically, or after a certain action. Green dot in the corner of session’s icon indicates the connected status.

You can create a new session by doing either of the following:

  • Open a query console or view database object’s data in data editor. As a result, under the data source node in the Services tool window, the new session node appears with a client node under it.
    1. For a query console, the session will be connected once you perform an action that requires interaction with the database. For example, once you run a query.
    2. For a table, the session is connected automatically, as PyCharm requires an active connection to request the table data from the database, receive it, and display it in the data editor.
  • Perform an action that requires interaction with the database. For example, run a stored procedure or run a script via run configurations. As a result, the new connected session node appears under the data source node in the Services tool window.

Подключение к удаленной postgresql из Pycharm

Добрый день! У нас есть сервер для разработки на котором установлена Centos 7 и postgres-9.5, не получается в Pycharm подключиться к удаленному серверу. Конфиг /var/lib/pgsql/9.5/data/pg_hba.conf после добавления последней строки выглядит так:

# TYPE DATABASE USER ADDRESS METHOD local all all peer host all all 127.0.0.1/32 password host all all ::1/128 password host all all 0.0.0.0/0 md5 

Настройки pycharm

iptables временно отключили В Pycharm далаю такую конфигурацию

Отслеживать

задан 8 окт 2016 в 8:31

381 2 2 серебряных знака 15 15 бронзовых знаков

0

Сортировка: Сброс на вариант по умолчанию

Знаете кого-то, кто может ответить? Поделитесь ссылкой на этот вопрос по почте, через Твиттер или Facebook.

  • postgresql
  • centos
  • postgresql9.5

Как в PyCharm перенести базу данных PostgreSQL

Admin 05.10.2020 , обновлено: 08.01.2021 PostgreSQL

Будем переносить локальную базу данных PostgreSQL на удаленные сервер с помощью программы PyCharm.

Чтобы избежать проблем с пользователями при работе с базами данных на разных системах надо придерживаться одинаковых имен, иначе при импорте возникнут ошибки:

Command was: ALTER TABLE public.users_settings_id_seq OWNER TO «UserName»;
pg_restore: from TOC entry 219; 1259 57835 TABLE volumes UserName
pg_restore: error: could not execute query: ERROR: role «UserName» does not exist

В локальной базе данных ставим курсор на public:

И выбираем Export with ‘pg_dump’:

Выбираем параметры как на скрине ниже и экспортируем в удобную нам папку:

Теперь для удаленного сервера также ставим курсор на директорию public, но теперь выбираем пункт Restore with ‘pg_restore’:

Этот процесс не самый быстрый. Возможно, в следующий раз разберем импортирование другим способом.

Читайте также

У сайта нет цели самоокупаться, поэтому на сайте нет рекламы. Но если вам пригодилась информация, можете лайкнуть страницу, оставить комментарий или отправить мне подарок на чашечку кофе.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *