Ubuntu 安装Postgres数据库,Windows 安装PgAdmin进行远程管理,Django远程连接 手记

news/2024/7/7 20:02:11

Ubuntu通过SSH操作:

1. 安装postgres

~$ sudo apt-get install postgresql


2. 添加数据库用户:
sudo -u postgres createuser -P YOURNAME

3. 别忘了配置密码,作为超级用户。

4. 创建用户名对应的数据库

sudo -u postgres createdb YOURNAME 

5. 设置其它机器上对postgres的访问

修改/etc/postgresql/9.1/main/pg_hba.conf:

host all all 0.0.0.0/0 md5 #0.0.0.0为地址段,0为多少二进制位

例如:192.168.0.0/16代表192.168.0.1-192.168.255.254

6. 修改/etc/postgresql/9.1/main/postgresql.conf

listen_address = '*'

只要取消注释即可

7. 重启数据库

sudo /etc/init.d/postgresql restart


Windows操作:

1. 安装PgAdmin

http://www.postgresql.org/download/windows/

2. 启动pgAdmin III,点击“添加一个服务器连接”

3. 设置如下:

名称:随便

主机:Ubuntu的IP地址

端口号:默认5432

服务:空

数据库:刚才创建的数据库

用户名和密码填上刚才创建的即可

OK!!恭喜成功


如果通过Django,可以这样操作:

1. 安装 psycopg

http://initd.org/psycopg/download/

安装成功后在python shell输入以下验证安装成功:import psycopg

2. 修改settings.py

DATABASES = {
    'default': {
        'ENGINE': 'postgresql_psycopg2',
        'NAME': 'automation',
        'USER': '创建的用户名',                      # Not used with sqlite3.
        'PASSWORD': '密码',                  # Not used with sqlite3.
        'HOST': 'Ubuntu的IP地址',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
    }

}

3. 验证配置正确:python manage.py validate

4. 创建完Django模型后,数据库同步数据:python manage.py syncdb


至此大功告成



http://www.niftyadmin.cn/n/3649227.html

相关文章

通用网页数据采集系统的架构和运行机理

VersionDateCreatorDescription1.0.0.12004-9-06郑昀 掌上灵通草稿摘要:本文档详细介绍了网页数据采集系统的架构和运行机理。第一章简单介绍了Spider的设计意图和模块构成。第二章简单介绍了Spider.Crawler层如何抓取网页并落地。第三章简单介绍了Spider.Parser层如…

Android源码学习之ActivityManager框架解析

ActivityManager在操作系统中有重要的作用,本文利用操作系统源码,逐步理清ActivityManager的框架,并从静态类结构图和动态序列图两个角度分别进行剖析,从而帮助开发人员加强对系统框架及进程通信机制的理解。 ActivityManager的作…

使用flutter_launcher_icons自动生成Flutter应用程序图标

I’ve been working on a Flutter application for the better half of this year, and as we get closer to release, I realized I hadn’t set an app icon yet. I initially went ahead and set my icons with Xcode and Android Studio, but after finding the flutter_la…

开源软件许可探究

选择了“原创”标签,其实内容并非完全原创 今天研究了一下开源软件,本文将自己的理解各篇转载的文章做个归并和整理 如今开源的软件已经越来越被广泛使用,各种专利纠纷也越来越多。工作上要求对开源协议的理解也很迫切,做技术架构…

Android框架层之音频管理器AudioManager的使用

为了能通过程序管理系统音量,或者直接让系统静音,可以使用AudioManager来实现,同时也用到MediaPlayer对音频进行控制。 下面是一个简单的对音频控制的例子(注:音频文件需要在res文件夹下创建一个raw文件夹,…

Ubuntu安装psycopg2小记

作者:Wally Yu 在windows上和Linux上安装psycopg2都遇到了点小插曲,记录如下 Windows下: 1. 前往官网下载源代码 http://www.initd.org/psycopg/ 2. 解压 3. 运行python setup.py install报错 解决办法:官网提供了windows…

ecmascript v3_节点v12中的新ECMAScript模块简介

ecmascript v3介绍 (Introduction) If you’re familiar with popular JavaScript frontend frameworks like React and Angular, then the concept of ECMAScript won’t be entirely new to you. ES Modules have the import and export syntax we see often in frontend fra…

Python 的OCR机制分析验证码

在用QTP做automation的时候总会遇到烦人的验证码,尝试从技术角度出发去解决,不知为什么QTP10之后对OCR的识别能力有所下降,无奈考虑其他的办法 今天搜索了大量的网站,终于有了一些小成就,不过还是只能识别一些简单的验…