django migrate error fe_sendauth: no password supplied

本文记录了在PostgreSQL 9.1版本中配置流复制时遇到的问题及其解决方法,包括因未设置正确密码导致的连接失败问题,以及由于用户缺少复制权限引起的故障。

在初始化PostgreSQL的流复制时,记下参数不对发生的两个问题及处理办法。

环境:
DB:PostgreSQL 9.1
VMWARE:6

前期准备略(包含热机和备机的安装及参数设置)。

问题1 参数配好启动备机时,日志显示
FATAL: could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

FATAL:  could not connect to the primary server: fe_sendauth: no password supplied

该问题显示是密码没有提供,
但是检查.pgpass和primary_conninfo以及把primary_conninfo里面的内容拷贝出来psql一下
都是可以连接的,重新检查下参数,发现standby机子上的参数standby_mode这个参数没有调整,修改,使之standby_mode = on,再重启standby机子,结果这个问题就解决了,测试过程中发现,primary_conninfo中不设置password也会出现这个问题。

接来下却发生了下面这个问题。

问题2. standby日志显示:
FATAL: could not connect to the primary server: FATAL: must be replication role to start walsender

FATAL:  could not connect to the primary server: FATAL:  must be replication role to start walsender

FATAL:  could not connect to the primary server: FATAL:  must be replication role to start walsender

FATAL:  could not connect to the primary server: FATAL:  must be replication role to start walsender

FATAL:  could not connect to the primary server: FATAL:  must be replication role to start walsender

在master端的日志显示:
FATAL: must be replication role to start walsender

FATAL:  must be replication role to start walsender
FATAL:  must be replication role to start walsender
FATAL:  must be replication role to start walsender
FATAL:  must be replication role to start walsender
FATAL:  must be replication role to start walsender

从日志上也可以看出,walsender的角色必须是replication,回到master端查看repuser,果然是没有配replication权限,只是普通用户。改之。

postgres=# CREATE USER repuser  REPLICATION LOGIN  CONNECTION LIMIT 3   ENCRYPTED PASSWORD 'repuser';
CREATE ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 repuser   | Replication                                   +| {}
           | 3 connections

再次重启slave端的Postgresql,这次正常了。 查看master端的视图pg_stat_replication

postgres=# select procpid,usename,application_name,client_addr,client_port,state,sync_state from pg_stat_replication;
 procpid | usename | application_name |  client_addr  | client_port |   state   | sync_state
---------+---------+------------------+---------------+-------------+-----------+------------
   11816 | repuser | walreceiver      | 192.168.2.134 |       41205 | streaming | async
(1 row)

在本次创建user的过程发现,9.1版本的PG创建一个super用户时会默认带出replication权限。

postgres=# create user t_kenyon SUPERUSER ;
CREATE ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 repuser   | Replication                                   +| {}
           | 3 connections                                  |
 t_kenyon  | Superuser, Replication                         | {}

总结:
repuser在9.1后已经不需要配置super权限,在配置流复制和其他复杂配置时需要小心仔细,避免一些不必要的麻烦。

python manage.py migrate ====NN_DATA_CIRCLE_PROFILE is staging 2025-09-10 10:41:53,174 - Defense_case_dao - ERROR - defense_case_dao.py[line:51]-init class 'CaseDAO' error 2025-09-10 10:41:53,525 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = prediction_smoke_config 2025-09-10 10:41:53,545 - defense_dao - ERROR - defense_dao.py[line:1784]-get fields map failed, error: connection to server at "10.94.83.90", port 5432 failed: fe_sendauth: no password supplied 2025-09-10 10:41:53,586 - Defense_case_dao - ERROR - defense_case_dao.py[line:51]-init class 'CaseDAO' error 2025-09-10 10:41:53,625 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = smoke_task_info 2025-09-10 10:41:53,625 - sync_service - ERROR - CI_data_sync_service.py[line:34]-init class 'CiDataSyncService' error 2025-09-10 10:41:53,669 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = smoke_task_info 2025-09-10 10:41:53,669 - DI_sync_service - ERROR - DI_data_sync_service.py[line:27]-init class 'DiDataSyncService' error 2025-09-10 10:41:53,698 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = branch_transfer_map 2025-09-10 10:41:53,735 - hard_case_sync_service - ERROR - hard_case_sync_service.py[line:71]-init class 'HardCaseSyncService' error 2025-09-10 10:41:53,992 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = branch_transfer_map 2025-09-10 10:41:54,016 - hard_case_sync_service - ERROR - hard_case_sync_service.py[line:71]-init class 'HardCaseSyncService' error 2025-09-10 10:41:54,058 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = smoke_task_info 2025-09-10 10:41:54,058 - sync_service - ERROR - CI_data_sync_service.py[line:34]-init class 'CiDataSyncService' error 2025-09-10 10:41:54,134 - defense_dao - ERROR - defense_dao.py[line:1652]-t_param doesn't have val where name = smoke_task_info 2025-09-10 10:41:54,134 - DI_sync_service - ERROR - DI_data_sync_service.py[line:27]-init class 'DiDataSyncService' error 2025-09-10 10:41:54,165 - defense_dao - ERROR - defense_dao.py[line:1784]-get fields map failed, error: connection to server at "10.94.83.90", port 5432 failed: fe_sendauth: no password supplied Traceback (most recent call last): File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection self.connect() File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 263, in connect self.connection = self.get_new_connection(conn_params) File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\postgresql\base.py", line 215, in get_new_connection connection = Database.connect(**conn_params) File "D:\python3.9.10\lib\site-packages\psycopg2\__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: connection to server at "10.94.83.90", port 5432 failed: fe_sendauth: no password supplied The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\z60102574\Desktop\CI_Backend\manage.py", line 23, in <module> main() File "C:\Users\z60102574\Desktop\CI_Backend\manage.py", line 19, in main execute_from_command_line(sys.argv) File "D:\python3.9.10\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line utility.execute() File "D:\python3.9.10\lib\site-packages\django\core\management\__init__.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "D:\python3.9.10\lib\site-packages\django\core\management\base.py", line 402, in run_from_argv self.execute(*args, **cmd_options) File "D:\python3.9.10\lib\site-packages\django\core\management\base.py", line 448, in execute output = self.handle(*args, **options) File "D:\python3.9.10\lib\site-packages\django\core\management\base.py", line 96, in wrapped res = handle_func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\core\management\commands\migrate.py", line 114, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "D:\python3.9.10\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "D:\python3.9.10\lib\site-packages\django\db\migrations\loader.py", line 58, in __init__ self.build_graph() File "D:\python3.9.10\lib\site-packages\django\db\migrations\loader.py", line 235, in build_graph self.applied_migrations = recorder.applied_migrations() File "D:\python3.9.10\lib\site-packages\django\db\migrations\recorder.py", line 81, in applied_migrations if self.has_table(): File "D:\python3.9.10\lib\site-packages\django\db\migrations\recorder.py", line 57, in has_table with self.connection.cursor() as cursor: File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 323, in cursor return self._cursor() File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 299, in _cursor self.ensure_connection() File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection self.connect() File "D:\python3.9.10\lib\site-packages\django\db\utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection self.connect() File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\base\base.py", line 263, in connect self.connection = self.get_new_connection(conn_params) File "D:\python3.9.10\lib\site-packages\django\utils\asyncio.py", line 26, in inner return func(*args, **kwargs) File "D:\python3.9.10\lib\site-packages\django\db\backends\postgresql\base.py", line 215, in get_new_connection connection = Database.connect(**conn_params) File "D:\python3.9.10\lib\site-packages\psycopg2\__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: connection to server at "10.94.83.90", port 5432 failed: fe_sendauth: no password supplied
最新发布
09-11
`django.db.utils.OperationalError: connection to server at "10.94.83.90", port 5432 failed: fe_sendauth: no password supplied` 错误表明在连接到 PostgreSQL 数据库时,没有提供有效的密码。可以通过以下几种方法解决该问题: #### 检查数据库配置 要确保 `settings.py` 文件中的数据库配置包含正确的密码: ```python DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'your_database_name', 'USER': 'your_username', 'PASSWORD': 'your_password', 'HOST': '10.94.83.90', 'PORT': '5432', } } ``` #### 检查密码是否正确 确认所使用的数据库用户密码是否正确,可以通过以下命令尝试手动连接到数据库进行验证: ```bash psql -h 10.94.83.90 -p 5432 -U your_username -d your_database_name ``` 执行该命令后,系统会提示输入密码,输入密码并回车。若能成功连接,则表明密码正确;若连接失败,则需要重置密码。 #### 检查数据库认证配置 检查 PostgreSQL 的 `pg_hba.conf` 文件,确保认证方式配置正确。该文件通常位于 `/etc/postgresql/<version>/main/pg_hba.conf`。确保针对该用户和数据库的认证方式为 `md5` 或 `password`,示例如下: ```plaintext host your_database_name your_username 10.94.83.90/32 md5 ``` 修改 `pg_hba.conf` 文件后,需要重新加载 PostgreSQL 配置: ```bash sudo systemctl reload postgresql ``` #### 检查防火墙设置 确保防火墙允许从 Django 应用服务器连接到 PostgreSQL 服务器的 5432 端口。可以使用以下命令开放 5432 端口: ```bash sudo ufw allow 5432 ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值