企业网站排名优化价格如何评价网站是否做的好坏

当前位置: 首页 > news >正文

企业网站排名优化价格,如何评价网站是否做的好坏,企业网页设计,seo推广小分享初始化集群 ​专栏内容#xff1a; postgresql内核源码分析手写数据库toadb并发编程 ​开源贡献#xff1a; toadb开源库 个人主页#xff1a;我的主页 管理社区#xff1a;开源数据库 座右铭#xff1a;天行健#xff0c;君子以自强不息#xff1b;地势坤#xff0c;君…初始化集群 ​专栏内容 postgresql内核源码分析手写数据库toadb并发编程 ​开源贡献 toadb开源库 个人主页我的主页 管理社区开源数据库 座右铭天行健君子以自强不息地势坤君子以厚德载物. 系列文章 初始化集群数据库服务管理 一、前言 postgresql 数据库是一款通用的关系型数据在开源数据库中能与商业数据媲美在业界也越来越流行。 因为是开源数据库不仅公开源码还有很多使用案例好用的插件所以它的慢慢变成了数据库的先驱和标准通过postgresql可以很好从使用到原理彻底搞懂 如果是学习编程也可以学到丰富的编程知识数据结构编程技巧它里面还有很多精妙的架构设计分层思想可以灵活定制的思想。 本专栏主要介绍postgresql 入门使用数据库维护管理通过这些使用来了解数据库原理慢慢了解postgresql是什么样的数据库能做那些事情以及如何做好服务最关键的是这些知识都是面试的必备项。 二、概述 本文主要介绍postgresql 的数据库集群它的初始化配置以及它的物理结构。 在源码编译安装后第一步就是初始化集群 而通过安装包安装后已经初始化了一个默认的数据库集群启动服务后就可以直接进行SQL命令操作。 而在我们应用部署时不同的应用往往使用不同的数据库集群目录在物理上进行隔离那么我们就需要对不同应用分别初始化各自的数据库集群。 三、原理 我们知道数据库主要是帮助存储和管理数据方便我们检索那么数据库存储数据的目录这在postgresql中叫做集群目录,有些翻译的叫集簇目录。 集群目录下面存放用户的数据如创建的表用户索引等数据外还有数据库组织数据如数据库与表的映射关系数据库的数量表的结构定义等我们称之为数据字典 另外还有一类数据是为了数据库服务运行稳定高性能的辅助数据如系统字典的缓存数据空闲空间的管理数据等等。 数据库服务运行时就会从这个目录下进行加载所以这个目录非常重要在实际项目中都会有专门的系统用户才可以操作同时还要对它进行冷备还要进行各种策略的热备。 呃泄漏了删库跑路原来这样子的什么都没说。。。 三、命令介绍 在安装目录下的bin目录中有初始化数据库集群的命令 initdb我们一起来看下它的介绍。

安装后的目录大概有以下四个子目录

bin 命令目录 include 是开发所需的头文件

lib是开发所需的库share中包括模版配置文件插件等

[senllanghatch postgres]\( ll total 16 drwxr-xr-x. 2 senllang develops 4096 Aug 2 09:26 bin drwxr-xr-x. 6 senllang develops 4096 Aug 2 09:24 include drwxr-xr-x. 4 senllang develops 4096 Aug 2 09:26 lib drwxr-xr-x. 7 senllang develops 4096 Aug 2 09:26 share [senllanghatch postgres]\) cd bin/查看帮助 [senllanghatch bin]\( ./initdb --help initdb initializes a PostgreSQL database cluster.Usage:initdb [OPTION]... [DATADIR]Options:-A, --authMETHOD default authentication method for local connections--auth-hostMETHOD default authentication method for local TCP/IP connections--auth-localMETHOD default authentication method for local-socket connections[-D, --pgdata]DATADIR location for this database cluster-E, --encodingENCODING set default encoding for new databases-g, --allow-group-access allow group read/execute on data directory--icu-localeLOCALE set ICU locale ID for new databases--icu-rulesRULES set additional ICU collation rules for new databases-k, --data-checksums use data page checksums--localeLOCALE set default locale for new databases--lc-collate, --lc-ctype, --lc-messagesLOCALE--lc-monetary, --lc-numeric, --lc-timeLOCALEset default locale in the respective category fornew databases (default taken from environment)--no-locale equivalent to --localeC--locale-provider{libc|icu}set default locale provider for new databases--pwfileFILE read password for the new superuser from file-T, --text-search-configCFGdefault text search configuration-U, --usernameNAME database superuser name-W, --pwprompt prompt for a password for the new superuser-X, --waldirWALDIR location for the write-ahead log directory--wal-segsizeSIZE size of WAL segments, in megabytesLess commonly used options:-c, --set NAMEVALUE override default setting for server parameter-d, --debug generate lots of debugging output--discard-caches set debug_discard_caches1-L DIRECTORY where to find the input files-n, --no-clean do not clean up after errors-N, --no-sync do not wait for changes to be written safely to disk--no-instructions do not print instructions for next steps-s, --show show internal settings-S, --sync-only only sync database files to disk, then exitOther options:-V, --version output version information, then exit-?, --help show this help, then exitIf the data directory is not specified, the environment variable PGDATA is used.Report bugs to pgsql-bugslists.postgresql.org. PostgreSQL home page: https://www.postgresql.org/ 参数说明 常用的参数主要有 -D 指定集群目录所在的路径这是必选的参数比如~/testdemo那么testdemo就是集群目录, 当然也可以设置环境变量 PGDATA 来代替-D-U 指定数据库的超级管理员用户名它具有所有权限这是可选参数如果不指定默认数据库超级管理员与当前的系统用户名 同名-W 提示输入密码这个密码是超级管理员用户的登陆密码这也是可选参数默认为空 其它参数可以在后继学习中再了解。 四、初始化集群 了解了初始化集群命令后现在让我们初始化一个属于我们自己的数据库集群。 在当前目录下创建testdemo的数据库集群目录同时将数据库超级用户命名为postgres [senllanghatch bin]\) ./initdb -D testdemo -W -U postgres The files belonging to this database system will be owned by user senllang. This user must also own the server process.Using default ICU locale en_US. Using language tag en-US for ICU locale en_US. The database cluster will be initialized with this locale configuration:provider: icuICU locale: en-USLC_COLLATE: en_US.UTF-8LC_CTYPE: en_US.UTF-8LC_MESSAGES: en_US.UTF-8LC_MONETARY: en_US.UTF-8LC_NUMERIC: en_US.UTF-8LC_TIME: en_US.UTF-8 The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to english.Data page checksums are disabled.Enter new superuser password: Enter it again:creating directory testdemo … ok creating subdirectories … ok selecting dynamic shared memory implementation … posix selecting default max_connections … 100 selecting default shared_buffers … 128MB selecting default time zone … Asia/Shanghai creating configuration files … ok running bootstrap script … ok performing post-bootstrap initialization … ok syncing data to disk … okinitdb: warning: enabling trust authentication for local connections initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or –auth-local and –auth-host, the next time you run initdb.Success. You can now start the database server using:pg_ctl -D testdemo -l logfile start这样在当前目录下就生成了一个testdemo的目录里面有好多子目录和文件下面我们来认识一下。 五、集群目录 [senllanghatch bin]\( cd testdemo/ [senllanghatch testdemo]\) ll total 56 drwx——. 5 senllang develops 33 Sep 2 14:42 base drwx——. 2 senllang develops 4096 Sep 2 14:42 global drwx——. 2 senllang develops 6 Sep 2 14:42 pg_commit_ts drwx——. 2 senllang develops 6 Sep 2 14:42 pg_dynshmem -rw——-. 1 senllang develops 5711 Sep 2 14:42 pg_hba.conf -rw——-. 1 senllang develops 2640 Sep 2 14:42 pg_ident.conf drwx——. 4 senllang develops 68 Sep 2 14:42 pg_logical drwx——. 4 senllang develops 36 Sep 2 14:42 pg_multixact drwx——. 2 senllang develops 6 Sep 2 14:42 pg_notify drwx——. 2 senllang develops 6 Sep 2 14:42 pg_replslot drwx——. 2 senllang develops 6 Sep 2 14:42 pg_serial drwx——. 2 senllang develops 6 Sep 2 14:42 pg_snapshots drwx——. 2 senllang develops 25 Sep 2 14:42 pg_stat drwx——. 2 senllang develops 6 Sep 2 14:42 pg_stat_tmp drwx——. 2 senllang develops 18 Sep 2 14:42 pg_subtrans drwx——. 2 senllang develops 6 Sep 2 14:42 pg_tblspc drwx——. 2 senllang develops 6 Sep 2 14:42 pg_twophase -rw——-. 1 senllang develops 3 Sep 2 14:42 PG_VERSION drwx——. 3 senllang develops 60 Sep 2 14:42 pg_wal drwx——. 2 senllang develops 18 Sep 2 14:42 pg_xact -rw——-. 1 senllang develops 88 Sep 2 14:42 postgresql.auto.conf -rw——-. 1 senllang develops 29708 Sep 2 14:42 postgresql.conf先来看几个重要的目录和文件 base 目录 它里面存储各个database中的数据包括tableindex, sequence, view等等pg_wal 目录 存放我们常说的redo日志log 目录 数据库服务运行的日志上图中没有默认没有打开日志输出到文件的开关postgresql.conf 数据库服务的配置文件比如数据库服务的监听IP端口等大量配置pg_hba.conf 主机访问控制的配置文件默认只能本机登陆如果需要远程访问就需要配置许可 其它文件我们后面慢慢了解 六、配置文件 我们重点介绍 数据库配置文件和主机访问控制配置先来介绍几个入门级参数这样就可以解决刚开始使用的问题其它参数会随着其它功能介绍一起了解。 数据库配置 默认参数的前面都会加 # ,如果需要修改的话需要去掉前面的#修改才能生效。 监听配置 默认localhost 和 5432如果要远程客户端访问可以修改为具体IP或* listen_addresses *

port 5432数据库连接数

数据库服务启动时内存分配锁的分配都和连接数有关当然也不能无限大默认连接数为100这里可以根据自己的需求修改, 越大占用的内存和系统资源越多够用即可 max_connections 100数据库缓存大小 在select查询或insert插入数据时并不是直接操作磁盘上的文件而是操作缓存中的数据如果数据不在缓存中才会与磁盘进行交互所以缓存当然是越大越好能把需要的数据都加载进来那性能就会提升。 默认是128MB当然根据自己的数据量和机器的内存来定如果只是尝试一下默认也足够了如果发现磁盘的IO很高那就需要适当调大一些 shared_buffers 128MB 数据库运行日志 调试过程序的都知道运行日志的重要性默认是关闭的也就是不输出到文件中建议打开这样在发生异常时可以通过运行日志文件来分析 logging_collector on 主机访问控制 数据库有严格的访问控制可以精确到某个database, user, 或网段它的配置格式如下

local DATABASE USER METHOD [OPTIONS]

host DATABASE USER ADDRESS METHOD [OPTIONS]

hostssl DATABASE USER ADDRESS METHOD [OPTIONS]

hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]

hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS]

hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS]我们想到配置远程访问比如图形化客户端访问可以加入一行, 允许所有IP可以访问所有数据库必须使用密码校验。

host all all 0.0.0.0/0 md5七、总结 通过本文分享了postgresql 数据存储目录-数据集群目录概念初始化数据库集群以及一些入门级参数配置期待您的反馈和加入。 结尾 非常感谢大家的支持在浏览的同时别忘了留下您宝贵的评论如果觉得值得鼓励请点赞收藏我会更加努力 作者邮箱studysenllang.onaliyun.com 如有错误或者疏漏欢迎指出互相学习。 注未经同意不得转载