在这篇文章中,我们将带领您了解如何重置postgres中的序列并用新数据填充id列?的全貌,同时,我们还将为您介绍有关centos7下源码编译安装php支持PostgreSQLpostgresql手册
在这篇文章中,我们将带领您了解如何重置 postgres 中的序列并用新数据填充 id 列?的全貌,同时,我们还将为您介绍有关centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、postgresql – Docker持久数据中的Postgres、postgresql – Postgres中的“隐式序列”和“隐式索引”是什么意思?、postgresql – Postgres作为Processmaker中的默认数据库的知识,以帮助您更好地理解这个主题。
本文目录一览:- 如何重置 postgres 中的序列并用新数据填充 id 列?
- centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教
- postgresql – Docker持久数据中的Postgres
- postgresql – Postgres中的“隐式序列”和“隐式索引”是什么意思?
- postgresql – Postgres作为Processmaker中的默认数据库
如何重置 postgres 中的序列并用新数据填充 id 列?
我有一张超过百万行的表。我需要重置序列并使用新值(1、2、3、4…等…)重新分配 id 列。有什么简单的方法可以做到这一点吗?
答案1
小编典典如果您不想保留 id 的顺序,那么您可以
ALTER SEQUENCE seq RESTART WITH 1;UPDATE t SET idcolumn=nextval(''seq'');
我怀疑是否有一种简单的方法可以按照您选择的顺序执行此操作,而无需重新创建整个表。
centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教
1. 下载源码
$ mkdir /usr/downloads $ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz $ tar -xvf php-5.6.20.tar.gz $ mv php-5.6.20 /usr/local/src $ cd !$ & cd php-5.6.20
2. 阅读安装指导
$ ls -also $ less README $ less INSTALL
3. 安装依赖包
$ yum install apr apr-util apr-devel apr-util-devel prce lynx
4. 安装httpd
$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz $ tar -xvf httpd-2.4.20.tar.gz $ cd httpd-2.4.20 $ ./configure \ --prefix=/usr/local/programs/apache2 \ --enable-rewrite \ --enable-so \ --enable-headers \ --enable-expires \ --with-mpm=worker \ --enable-modules=most \ --enable-deflate \ --enable-module=shared $ make $ make install $ cd /usr/local/programs/apache2 $ cp bin/apachectl /etc/init.d/httpd ## 复制启动脚本 $ /etc/init.d/httpd start ## 启动apache服务器,访问http://localhost/ $ egrep -v ''^[ ]*#|^$'' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服务器的配置 ## 将apache加入系统服务 vi /etc/rc.d/rc.local ``` /usr/local/programs/apache2/bin/apachectl start ``` $ cat /etc/rc.local
4. 安装postgresql
立即学习“PHP免费学习笔记(深入)”;
$ yum install readline-devel ## 安装readline依赖 $ cd /usr/downloads $ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2 $ tar -xvf postgresql-9.5.0.tar.bz2 $ cd postgresql-9.5.0 $ ./configure --prefix=/usr/local/programs/postgresql $ make $ su $ make install $ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享动态库 $ cd /usr/local/programs/postgresql $ bin/psql --version ## 检查运行情况 ## 开始对postgresql的配置 $ vi /etc/profile.d/postgresql.sh ## 增加环境变量,不推荐直接在/etc/profile中添加,系统更新升级时会需要merge ``` PATH=/usr/local/programs/postgresql:$PATH export PATH ``` $ source /etc/profile ## 更新环境变量 ## 增加用户和其他文件夹 $ adduser postgres $ passwd postgres $ mkdir /usr/local/programs/postgresql/logs $ mkdir /usr/local/programs/postgresql/data $ chown postgres /usr/local/programs/postgresql/data $ su - postgres ## 初始化数据库 $ ./bin/initdb -D ./data $ ./bin/createdb test $ ./bin/psql test ## 已有数据库,可导入data文件夹后尝试root访问,假如带密码,可能需要进一步研究下 $ ./bin/postgres -D ./data >./logs/start-log-1.log 2>&1 & $ ./bin/psql --list ##列出数据库 ## ok,安装完成 ## 自定义设置,权限控制等,可以跳过,等熟悉使用后再做 ## 编辑数据库配置及权限文件: $ vi /usr/local/programs/postgresql/data/postgresql.conf ## 数据库配置文件 $ chown postgres postgresql.conf $ chmod 644 postgresql.conf $ vi /usr/local/programs/postgresql/data/pg_hba.conf ## 权限文件 $ vi /usr/local/programs/postgresql/data/pg_ident.conf ## 设置开机自启动: $ vi /etc/rc.d/rc.local ## 添加如下内容 ``` /usr/local/programs/postgresql/bin/postgresql start ```
5. 安装php
## 源码已经在第一步中下载,现在开始安装: $ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel $ ./configure \ --prefix=/usr/local/programs/php \ --with-apxs2=/usr/local/programs/apache2/bin/apxs \ --with-zlib \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-zlib-dir \ --enable-mbstring \ --with-pgsql=/usr/local/programs/postgresql \ --with-pdo-pgsql=/usr/local/programs/postgresql $ make $ make test > Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt] XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags > Bug #67296 (filter_input doesn''t validate variables) [ext/filter/tests/bug49184.phpt] XFAIL REASON: See Bug #49184 > Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt] XFAIL REASON: Padding is not implemented yet > zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 > zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 >Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt] XFAIL REASON: bug is not fixed yet ## 查阅官方的bug,发现: > id=66582: status : Closed. Fixed in master (PHP7) > id=42718: status : Assigned > id=42718: reference to id=49184, unsolved for many years ## 那就不关心了,直接装吧 $ make install > You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path ## 那就按它说的设置吧 $ cp php.ini-development /usr/local/programs/php/lib/php.ini ``` include_path = ".;/usr/local/programs/php/lib/php" ## 然后,编辑httpd的设置,确保其能正确解析php文件 ``` ... LoadModule php5_module modules/libphp5.so ... AddType application/x-httpd-php .php AddType application/x-httpd-php-source .php5 ... <ifmodule dir_module> DirectoryIndex index.html index.php </ifmodule> ``` ## 重启httpd,测试 $ cd /usr/local/programs/apache2 $ bin/httpd -h $ bin/httpd -k stop $ bin/httpd -f conf/httpd.conf ## 默认设置的www页面在./htdocs/下,那就先去里面建一个测试页面吧 $ vi htdocs/index.php ``` <?php phpinfo(); ?> ``` $ curl http://localhost/index.php |grep postgresql #ok
后续应该做的事
* 1. 启动时,不需要要手动指定配置文件
* 2. php初始化www目录设置
* 3. php 用户、权限管理等
以上就介绍了centos 7下源码编译安装php支持PostgreSQL,包括了postgresql,centos 7方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
postgresql – Docker持久数据中的Postgres
https://www.andreagrandi.it/2015/02/21/how-to-create-a-docker-image-for-postgresql-and-persist-data/
http://container42.com/2013/12/16/persistent-volumes-with-docker-container-as-volume-pattern/
建议使用仅数据容器,然后让我的postgres容器链接到它.我无法理解的是;这有什么好处?据我所知,如果由于某种原因停靠机器关闭(例如,将其移动到另一台物理机器),仅数据容器会停止运行,并且所有内容都会丢失?我已经尝试在postgres容器中创建一个卷,但它实际上似乎并没有将任何内容保存到磁盘中.
这是我的docker文件.我究竟做错了什么?
FROM ubuntu MAINTAINER Andrew broadbent <andrew.broadbent@manchester.ac.uk> # Add the Postgresql PGP key to verify their Debian packages. # It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 # Add Postgresql''s repository. It contains the most recent stable release # of Postgresql,``9.3``. RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list # Install ``python-software-properties``,``software-properties-common`` and Postgresql 9.3 # There are some warnings (in red) that show up during the build. You can hide # them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 # Note: The official Debian and Ubuntu images automatically ``apt-get clean`` # after each ``apt-get`` # Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` USER postgres # Create a Postgresql role named ``docker`` with ``docker`` as the password and # then create a database `docker` owned by the ``docker`` role. # Note: here we use ``&&\`` to run commands one after the other - the ``\`` # allows the RUN command to span multiple lines. RUN /etc/init.d/postgresql start &&\ psql --command "CREATE USER docker WITH SUPERUSER PASSWORD ''docker'';" &&\ createdb -O docker docker # Complete configuration USER root RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf RUN echo "listen_addresses=''*''" >> /etc/postgresql/9.3/main/postgresql.conf # Expose the Postgresql port EXPOSE 5432 # Add VOLUMEs to allow backup of config,logs and databases RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql VOLUME ["/etc/postgresql","/var/log/postgresql","/var/lib/postgresql"] # Set the default command to run when starting the container USER postgres CMD ["/usr/lib/postgresql/9.3/bin/postgres","-D","/var/lib/postgresql/9.3/main","-c","config_file=/etc/postgresql/9.3/main/postgresql.conf"]
解决方法
docker mounting volumes on host
关于你的dockerfile,我建议你:
1)使用数据容器模式
2)通过指定:docker run -v [host-path]:[container-path] …将卷安装到主机上,这样数据将保存在主机的一个位置,并且在容器后不会丢失已移除.
参考:https://docs.docker.com/engine/tutorials/dockervolumes/#/mount-a-host-directory-as-a-data-volume
postgresql – Postgres中的“隐式序列”和“隐式索引”是什么意思?
my_database=# CREATE TABLE sites my_database-# ( my_database(# site_id_key serial primary key,my_database(# site_url VARCHAR(255),my_database(# note VARCHAR(255),my_database(# type INTEGER,my_database(# last_visited TIMESTAMP my_database(# ) ; NOTICE: CREATE TABLE will create implicit sequence "sites_site_id_key_seq" for serial column "sites_to_search.site_id_key" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "sites_pkey" for table "sites_to_search" CREATE TABLE
换句话说,索引和序列只是正常的索引和序列.它们只是由Postgresql自动创建,以便提供您在DDL中请求的保证和功能.
postgresql – Postgres作为Processmaker中的默认数据库
解决方法
这是下一版本4.0正在考虑的问题,但尚未做出正式决定.
所以,现在,如果你想使用ProcessMaker,它必须在MySQL数据库上.
关于如何重置 postgres 中的序列并用新数据填充 id 列?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos 7下源码编译安装php支持PostgreSQL postgresql手册 postgresql官网下载 postgresql视频教、postgresql – Docker持久数据中的Postgres、postgresql – Postgres中的“隐式序列”和“隐式索引”是什么意思?、postgresql – Postgres作为Processmaker中的默认数据库等相关知识的信息别忘了在本站进行查找喔。
本文标签: