1. 环境
postgreSQL-10
python2.7
ubuntu16.04 amd64
2. 问题
在完成django的环境配置后, 执行manage.py migrate出现连接错误. 网上没有同样的问题出现, 目前自己没找到.
(catmaid) user@ubuntu:~/catmaid/django/projects/mysite$ ../manage.py migrate catmaidTraceback (most recent call last):File "../manage.py", line 11, in <module>execute_from_command_line(sys.argv)File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_lineutility.execute()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in executedjango.setup()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setupapps.populate(settings.INSTALLED_APPS)File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populateapp_config.import_models()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_modelsself.models_module = import_module(models_module_name)File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module__import__(name)File "/home/bibao/catmaid/django/applications/catmaid/models.py", line 28, in <module>from .fields import Double3DField, Integer3DField, RGBAField, DownsampleFactorsFieldFile "/home/bibao/catmaid/django/applications/catmaid/fields.py", line 130, in <module>class Integer3DField(CompositeField):File "/home/bibao/catmaid/django/applications/catmaid/fields.py", line 38, in __init__cls.register_composite(connection)File "/home/bibao/catmaid/django/applications/catmaid/fields.py", line 47, in register_compositeconnection.cursor().cursor,File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 254, in cursorreturn self._cursor()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 229, in _cursorself.ensure_connection()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connectionself.connect()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__six.reraise(dj_exc_type, dj_exc_value, traceback)File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 213, in ensure_connectionself.connect()File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 189, in connectself.connection = self.get_new_connection(conn_params)File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connectionconnection = Database.connect(**conn_params)File "/home/bibao/.virtualenvs/catmaid/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync)django.db.utils.OperationalError: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
既然是连接错误那么就得看到底怎么错. 首先确认数据库运行正常.
(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ ps axf | grep post8119 pts/19 S+ 0:00 \_ grep --color=auto post7953 ? S 0:00 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf7955 ? Ss 0:00 \_ postgres: 10/main: checkpointer process7956 ? Ss 0:00 \_ postgres: 10/main: writer process7957 ? Ss 0:00 \_ postgres: 10/main: wal writer process7958 ? Ss 0:00 \_ postgres: 10/main: autovacuum launcher process7959 ? Ss 0:00 \_ postgres: 10/main: stats collector process7960 ? Ss 0:00 \_ postgres: 10/main: bgworker: logical replication launcher
绿色显示数据库正常运行. 然后查看Listen端口情况.
(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ netstat -anp |grep post(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)unix 2 [ ACC ] STREAM LISTENING 56644 - /var/run/postgresql/.s.PGSQL.5433
这明显是端口监听错误了. 应该改为5432的.
修改ps进程中的配置文件将端口从5433改为5432
重启数据库
(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ sudo vim /etc/postgresql/10/main/postgresql.conf(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ sudo service postgresql restart(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ netstat -anp |grep post(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)unix 2 [ ACC ] STREAM LISTENING 57089 - /var/run/postgresql/.s.PGSQL.5432(catmaid) bibao@ubuntu:~/catmaid/django/projects/mysite$ ps axf | grep post
这个时候就正常了. 重新迁移.
(catmaid) bibao@ubuntu:~/catmaid/django/projects$ ./manage.py migrateINFO 2018-06-29 10:00:32,086 CATMAID was unable to load the h5py library, which is an optional dependency. HDF5 tiles are therefore disabled. To enable, install h5py.WARNING 2018-06-29 10:00:32,306 NeuroML module could not be loaded.System check identified some issues:WARNINGS:?: Couldn't check history setup, missing database functions HINT: Migrate CATMAIDOperations to perform:Apply all migrations: admin, auth, authtoken, catmaid, contenttypes, guardian, performancetests, pgcompat, sessions, sites, taggitRunning migrations:Applying admin.0001_initial... OKApplying admin.0002_logentry_remove_auto_add... OKApplying catmaid.0006_add_history_table_support... OKApplying auth.0007_alter_validators_add_error_messages... OKApplying catmaid.0007_use_django_1_9_jsonfield... OKApplying catmaid.0008_update_transaction_log... OKApplying catmaid.0009_ensure_required_project_classes... OKApplying catmaid.0010_history_tracking_update... OKApplying catmaid.0011_fix_transaction_label_typo... OKApplying performancetests.0003_update_history_tables... OKApplying catmaid.0012_add_history_views... OKApplying catmaid.0013_add_missing_tnci_and_cnci_indices... OKApplying catmaid.0014_ensure_restriction_tables_have_auto_id... OKApplying catmaid.0015_fix_history_views... OKApplying catmaid.0016_import_meshes_as_volumes... OKApplying catmaid.0017_update_edge_indices... OKApplying catmaid.0018_add_stack_mirrors_and_groups... OKApplying catmaid.0019_add_import_permission... OKApplying catmaid.0020_delete_history_view_before_auth_user_update... OKApplying auth.0008_alter_user_username_max_length... OKApplying authtoken.0002_auto_20160226_1747... OKApplying catmaid.0021_recreate_history_view_after_auth_user_update... OKApplying catmaid.0022_add_reconstruction_sampler_tables... OKApplying catmaid.0023_update_edit_txids... OKApplying catmaid.0024_add_neuron_history_indices... OKApplying catmaid.0025_add_stats_summary_table... OKApplying catmaid.0026_add_additional_stats_indices... OKApplying catmaid.0027_update_data_view_name... OKApplying catmaid.0028_add_point_tables... OKApplying catmaid.0029_fix_stack_class_instance_constraints... OKApplying catmaid.0030_add_sampler_column... OKApplying catmaid.0031_add_interpolatable_sections_table... OKApplying catmaid.0032_add_simple_section_cache_table... OKApplying catmaid.0033_fix_node_query_cache_fkey... OKApplying catmaid.0034_add_node_query_cache_timestamp_and_unique_constraint... OKApplying catmaid.0035_add_skeleton_summary_table... OKApplying catmaid.0036_update_sampler_interval_constraints... OKApplying catmaid.0037_add_stack_zoom_factors... OKApplying catmaid.0038_add_missing_initial_skeleton_summaries... OKApplying sessions.0001_initial... OKApplying sites.0002_alter_domain_unique... OKINFO 2018-06-29 10:00:48,965 Creating ontology dummy project(catmaid) bibao@ubuntu:~/catmaid/django/projects$
问题解决.
最后找一下原因, 应该有两个方面比较可能:
1. 我之前安装postgresql-10失败,现状了9.5 这个可能会让9.5先占用了5432
2. 猜测10版本默认可能就直接有问题
最后, 其实不修改postgreSQL配置文件的话, 直接修改前面django的configuration.py应该也是没问题的, 那里可以指定端口, 知识我配置的时候采用了默认的值.
感谢:
https://blog.csdn.net/haohaibo031113/article/details/52832882
http://www.cnblogs.com/space-place/p/5257127.html