对于想了解RegularExpressionsinGrepCommandwith10Examples--reference的读者,本文将是一篇不可错过的文章,并且为您提供关于10LinuxDIGCom
对于想了解Regular Expressions in Grep Command with 10 Examples --reference的读者,本文将是一篇不可错过的文章,并且为您提供关于10 Linux DIG Command Examples for DNS Lookup--reference、10 Questions To Make Programming Interviews Less Expensive--reference、15 Advanced PostgreSQL Commands with Examples、15 Linux Split and Join Command Examples to Manage Large Files--reference的有价值信息。
本文目录一览:- Regular Expressions in Grep Command with 10 Examples --reference
- 10 Linux DIG Command Examples for DNS Lookup--reference
- 10 Questions To Make Programming Interviews Less Expensive--reference
- 15 Advanced PostgreSQL Commands with Examples
- 15 Linux Split and Join Command Examples to Manage Large Files--reference
Regular Expressions in Grep Command with 10 Examples --reference
Regular expressions are used to search and manipulate the text,based on the patterns. Most of the Linux commands and programming languages use regular expression.
Grep command is used to search for a specific string in a file. Please refer our earlier article for .
You can also use regular expressions with grep command when you want to search for a text containing a particular pattern. Regular expressions search for the patterns on each line of the file. It simplifies our search operation.This articles is part of a 2 article series.
This part 1 article covers grep examples for simple regular expressions. The future part 2 article will cover advanced regular expression examples in grep.
Let us take the file /var/log/messages file which will be used in our examples.
Example 1. Beginning of line ( ^ )
In grep command,caret Symbol ^ matches the expression at the start of a line. In the following example,it displays all the line which starts with the Nov 10. i.e All the messages logged on November 10.
$ grep "^Nov 10" messages.1 Nov 10 01:12:55 gs123 ntpd[2241]: time reset +0.177479 s Nov 10 01:17:17 gs123 ntpd[2241]: synchronized to LOCAL(0),stratum 10 Nov 10 01:18:49 gs123 ntpd[2241]: synchronized to 15.1.13.13,stratum 3 Nov 10 13:21:26 gs123 ntpd[2241]: time reset +0.146664 s Nov 10 13:25:46 gs123 ntpd[2241]: synchronized to LOCAL(0),stratum 10 Nov 10 13:26:27 gs123 ntpd[2241]: synchronized to 15.1.13.13,stratum 3
The ^ matches the expression in the beginning of a line,only if it is the first character in a regular expression. ^N matches line beginning with N.
Example 2. End of the line ( $)
Character $ matches the expression at the end of a line. The following command will help you to get all the lines which ends with the word “terminating”.
$ grep "terminating.$" messages Jul 12 17:01:09 cloneme kernel: Kernel log daemon terminating. Oct 28 06:29:54 cloneme kernel: Kernel log daemon terminating.
From the above output you can come to kNow when all the kernel log has got terminated. Just like ^ matches the beginning of the line only if it is the first character,$ matches the end of the line only if it is the last character in a regular expression.
Example 3. Count of empty lines ( ^$ )
Using ^ and $ character you can find out the empty lines available in a file. “^$” specifies empty line.
$ grep -c "^$" messages anaconda.log messages:0 anaconda.log:3
The above commands displays the count of the empty lines available in the messages and anaconda.log files.
Example 4. Single Character (.)
The special Meta-character “.” (dot) matches any character except the end of the line character. Let us take the input file which has the content as follows.
$ cat input 1. first line 2. hi hello 3. hi zello how are you 4. cello 5. aello 6. eello 7. last line
Now let us search for a word which has any single character followed by ello. i.e hello,cello etc.,
$ grep ".ello" input 2. hi hello 3. hi zello how are you 4. cello 5. aello 6. eello
In case if you want to search for a word which has only 4 character you can give grep -w “….” where single dot represents any single character.
Example 5. Zero or more occurrence (*)
The special character “*” matches zero or more occurrence of the prevIoUs character. For example,the pattern ’1*’ matches zero or more ’1′.
The following example searches for a pattern “kernel: *” i.e kernel: and zero or more occurrence of space character.
$ grep "kernel: *." * messages.4:Jul 12 17:01:02 cloneme kernel: ACPI: PCI interrupt for device 0000:00:11.0 disabled messages.4:Oct 28 06:29:49 cloneme kernel: ACPI: PM-Timer IO Port: 0x1008 messages.4:Oct 28 06:31:06 btovm871 kernel: sda: sda1 sda2 sda3 messages.4:Oct 28 06:31:06 btovm871 kernel: sd 0:0:0:0: Attached scsi disk sda . .
In the above example it matches for kernel and colon symbol followed by any number of spaces/no space and “.” matches any single character.
Example 6. One or more occurrence (\+)
The special character “\+” matches one or more occurrence of the prevIoUs character. ” \+” matches at least one or more space character.
If there is no space then it will not match. The character “+” comes under extended regular expression. So you have to escape when you want to use it with the grep command.
$ cat input hi hello hi hello how are you hihello$ grep "hi +hello" input
hi hello
hi hello how are you
In the above example,the grep pattern matches for the pattern ‘hi’,followed by one or more space character,followed by “hello”.
If there is no space between hi and hello it wont match that. However,* character matches zero or more occurrence.
“hihello” will be matched by * as shown below.
$ grep "hi *hello" input hi hello hi hello how are you hihello $
Example 7. Zero or one occurrence (\?)
The special character “?” matches zero or one occurrence of the prevIoUs character. “0?” matches single zero or nothing.
$ grep "hi \?hello" input hi hello hihello
“hi \?hello” matches hi and hello with single space (hi hello) and no space (hihello).
The line which has more than one space between hi and hello did not get matched in the above command.
Example 8.Escaping the special character (\)
If you want to search for special characters (for example: *,dot) in the content you have to escape the special character in the regular expression.
$ grep "127\.0\.0\.1" /var/log/messages.4 Oct 28 06:31:10 btovm871 ntpd[2241]: Listening on interface lo,127.0.0.1#123 Enabled
Example 9. Character Class ([0-9])
The character class is nothing but list of characters mentioned with in the square bracket which is used to match only one out of several characters.
$ grep -B 1 "[0123456789]\+ times" /var/log/messages.4 Oct 28 06:38:35 btovm871 init: open(/dev/pts/0): No such file or directory Oct 28 06:38:35 btovm871 last message repeated 2 times Oct 28 06:38:38 btovm871 pcscd: winscard.c:304:SCardConnect() Reader E-Gate 0 0 Not Found Oct 28 06:38:38 btovm871 last message repeated 3 times
Repeated messages will be logged in messages logfile as “last message repeated n times”. The above example searches for the line which has any number (0to9) followed by the word “times”. If it matches it displays the line before the matched line and matched line also.
With in the square bracket,using hyphen you can specify the range of characters. Like [0123456789] can be represented by [0-9]. Alphabets range also can be specified such as [a-z],[A-Z] etc. So the above command can also be written as
$ grep -B 1 "[0-9]\+ times" /var/log/messages.4
Example 10. Exception in the character class
If you want to search for all the characters except those in the square bracket,then use ^ (Caret) symbol as the first character after open square bracket. The following example searches for a line which does not start with the vowel letter from dictionary word file in linux.
$ grep -i "^[^aeIoU]" /usr/share/dict/linux.words 1080 10-point 10th 11-point 12-point 16-point 18-point 1st 2
First caret symbol in regular expression represents beginning of the line. However,caret symbol inside the square bracket represents “except” — i.e match except everything in the square bracket.
http://www.thegeekstuff.com/2011/01/regular-expressions-in-grep-command/
总结
以上是小编为你收集整理的Regular Expressions in Grep Command with 10 Examples --reference全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Express 相关文章
- • Express 入门 创建一个express文件
- • Express 路由 02
- • Express 中间件
- • Express 04 文件的上传和下载
- • Express 05 使用Node链接sqlite
- • Express 06 制作留言板项目 创建第一个
- • Express 06 制作留言板项目 完
- • Express VUE3 博客开发
- • Express VUE3 博客开发 用户token验证
- • python实现计算器功能
说明 |
---|
10 Linux DIG Command Examples for DNS Lookup--reference
by araJAN on
Dig stands for domain information groper.
Using dig command you can query DNS name servers for your DNS lookup related tasks. This article explains 10 examples on how to use dig command.
1. Simple dig Command Usage (Understand dig Output)
When you pass a domain name to the dig command,by default it displays the A record (the ip-address of the site that is queried) as shown below.In this example,it displays the A record of redhat.com in the “ANSWER SECTION” of the dig command output.
$ dig redhat.com; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY,status: NOERROR,id: 62863
;; flags: qr rd ra; QUERY: 1,ANSWER: 1,AUTHORITY: 4,ADDITIONAL: 3;; QUESTION SECTION:
;redhat.com. IN A;; ANSWER SECTION:
redhat.com. 37 IN A 209.132.183.81;; AUTHORITY SECTION:
redhat.com. 73 IN NS ns4.redhat.com.
redhat.com. 73 IN NS ns3.redhat.com.
redhat.com. 73 IN NS ns2.redhat.com.
redhat.com. 73 IN NS ns1.redhat.com.;; ADDITIONAL SECTION:
ns1.redhat.com. 73 IN A 209.132.186.218
ns2.redhat.com. 73 IN A 209.132.183.2
ns3.redhat.com. 73 IN A 209.132.176.100;; Query time: 13 msec
;; SERVER: 209.144.50.138#53(209.144.50.138)
;; WHEN: Thu Jan 12 10:09:49 2012
;; MSG SIZE rcvd: 164
The dig command output has the following sections:
- Header: This displays the dig command version number,the global options used by the dig command,and few additional header information.
- QUESTION SECTION: This displays the question it asked the DNS. i.e This is your input. Since we said ‘dig redhat.com’,and the default type dig command uses is A record,it indicates in this section that we asked for the A record of the redhat.com website
- ANSWER SECTION: This displays the answer it receives from the DNS. i.e This is your output. This displays the A record of redhat.com
- AUTHORITY SECTION: This displays the DNS name server that has the authority to respond to this query. Basically this displays available name servers of redhat.com
- ADDITIONAL SECTION: This displays the ip address of the name servers listed in the AUTHORITY SECTION.
- Stats section at the bottom displays few dig command statistics including how much time it took to execute this query
2. display Only the ANSWER SECTION of the Dig command Output
For most part,all you need to look at is the “ANSWER SECTION” of the dig command. So,we can turn off all other sections as shown below.
- +nocomments – Turn off the comment lines
- +noauthority – Turn off the authority section
- +noadditional – Turn off the additional section
- +nostats – Turn off the stats section
- +noanswer – Turn off the answer section (Of course,you wouldn’t want to turn off the answer section)
The following dig command displays only the ANSWER SECTION.
$ dig redhat.com +nocomments +noquestion +noauthority +noadditional +nostats; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com +nocomments +noquestion +noauthority +noadditional +nostats
;; global options: +cmd
redhat.com. 9 IN A 209.132.183.81
Instead of disabling all the sections that we don’t want one by one,we can disable all sections using +noall (this turns off answer section also),and add the +answer which will show only the answer section.
The above command can also be written in a short form as shown below,which displays only the ANSWER SECTION.
$ dig redhat.com +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com +noall +answer
;; global options: +cmd
redhat.com. 60 IN A 209.132.183.81
3. Query MX Records Using dig -t MX
To query MX records,pass MX as an argument to the dig command as shown below.
$ dig redhat.com MX +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com MX +noall +answer
;; global options: +cmd
redhat.com. 513 IN MX 5 mx1.redhat.com.
redhat.com. 513 IN MX 10 mx2.redhat.com.
You can also use option -t to pass the query type (for example: MX) as shown below.
$ dig -t MX redhat.com +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -t MX redhat.com +noall +answer
;; global options: +cmd
redhat.com. 489 IN MX 10 mx2.redhat.com.
redhat.com. 489 IN MX 5 mx1.redhat.com.
4. Query NS Records Using dig -t NS
To query the NS record use the type NS as shown below.
$ dig redhat.com NS +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com NS +noall +answer
;; global options: +cmd
redhat.com. 558 IN NS ns2.redhat.com.
redhat.com. 558 IN NS ns1.redhat.com.
redhat.com. 558 IN NS ns3.redhat.com.
redhat.com. 558 IN NS ns4.redhat.com.
You can also use option -t to pass the query type (for example: NS) as shown below.
$ dig -t NS redhat.com +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -t NS redhat.com +noall +answer
;; global options: +cmd
redhat.com. 543 IN NS ns4.redhat.com.
redhat.com. 543 IN NS ns1.redhat.com.
redhat.com. 543 IN NS ns3.redhat.com.
redhat.com. 543 IN NS ns2.redhat.com.
5. View ALL DNS Records Types Using dig -t ANY
To view all the record types (A,MX,NS,etc.),use ANY as the record type as shown below.
$ dig redhat.com ANY +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com ANY +noall +answer
;; global options: +cmd
redhat.com. 430 IN MX 5 mx1.redhat.com.
redhat.com. 430 IN MX 10 mx2.redhat.com.
redhat.com. 521 IN NS ns3.redhat.com.
redhat.com. 521 IN NS ns1.redhat.com.
redhat.com. 521 IN NS ns4.redhat.com.
redhat.com. 521 IN NS ns2.redhat.com.
(or) Use -t ANY
$ dig -t ANY redhat.com +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -t ANY redhat.com +noall +answer
;; global options: +cmd
redhat.com. 367 IN MX 10 mx2.redhat.com.
redhat.com. 367 IN MX 5 mx1.redhat.com.
redhat.com. 458 IN NS ns4.redhat.com.
redhat.com. 458 IN NS ns1.redhat.com.
redhat.com. 458 IN NS ns2.redhat.com.
redhat.com. 458 IN NS ns3.redhat.com.
6. View Short Output Using dig +short
To view just the ip-address of a web site (i.e the A record),use the short form option as shown below.
$ dig redhat.com +short 209.132.183.81
You can also specify a record type that you want to view with the +short option.
$ dig redhat.com ns +short ns2.redhat.com. ns3.redhat.com. ns1.redhat.com. ns4.redhat.com.
7. DNS Reverse Look-up Using dig -x
To perform a DNS reverse look up using the ip-address using dig -x as shown below
For example,if you just have an external ip-address and would like to kNow the website that belongs to it,do the following.
$ dig -x 209.132.183.81 +short www.redhat.com.
To view the full details of the DNS reverse look-up,remove the +short option.
$ dig -x 209.132.183.81; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> -x 209.132.183.81
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY,id: 62435
;; flags: qr rd ra; QUERY: 1,ADDITIONAL: 3;; QUESTION SECTION:
;81.183.132.209.in-addr.arpa. IN PTR;; ANSWER SECTION:
81.183.132.209.in-addr.arpa. 600 IN PTR www.redhat.com.;; AUTHORITY SECTION:
183.132.209.in-addr.arpa. 248 IN NS ns2.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns1.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns3.redhat.com.
183.132.209.in-addr.arpa. 248 IN NS ns4.redhat.com.;; ADDITIONAL SECTION:
ns1.redhat.com. 363 IN A 209.132.186.218
ns2.redhat.com. 363 IN A 209.132.183.2
ns3.redhat.com. 363 IN A 209.132.176.100;; Query time: 35 msec
;; SERVER: 209.144.50.138#53(209.144.50.138)
;; WHEN: Thu Jan 12 10:15:00 2012
;; MSG SIZE rcvd: 193
8. Use a Specific DNS server Using dig @dnsserver
By default dig uses the DNS servers defined in your /etc/resolv.conf file.
If you like to use a different DNS server to perform the query,specify it in the command line as @dnsserver.
The following example uses ns1.redhat.com as the DNS server to get the answer (instead of using the DNS servers from the /etc/resolv.conf file).
$ dig @ns1.redhat.com redhat.com; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> @ns1.redhat.com redhat.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY,id: 20963
;; flags: qr aa rd; QUERY: 1,ADDITIONAL: 4
;; WARNING: recursion requested but not available;; QUESTION SECTION:
;redhat.com. IN A;; ANSWER SECTION:
redhat.com. 60 IN A 209.132.183.81;; AUTHORITY SECTION:
redhat.com. 600 IN NS ns1.redhat.com.
redhat.com. 600 IN NS ns4.redhat.com.
redhat.com. 600 IN NS ns3.redhat.com.
redhat.com. 600 IN NS ns2.redhat.com.;; ADDITIONAL SECTION:
ns1.redhat.com. 600 IN A 209.132.186.218
ns2.redhat.com. 600 IN A 209.132.183.2
ns3.redhat.com. 600 IN A 209.132.176.100
ns4.redhat.com. 600 IN A 209.132.188.218;; Query time: 160 msec
;; SERVER: 209.132.186.218#53(209.132.186.218)
;; WHEN: Thu Jan 12 10:22:11 2012
;; MSG SIZE rcvd: 180
9. Bulk DNS Query Using dig -f (and command line)
Query multiple websites using a data file:
You can perform a bulk DNS query based on the data from a file.
First,create a sample names.txt file that contains the website that you want to query.
$ vi names.txt redhat.com centos.org
Next,execute dig -f as shown below,which will perform DNS query for the websites listed in the names.txt file and display the output.
$ dig -f names.txt +noall +answer redhat.com. 60 IN A 209.132.183.81 centos.org. 60 IN A 72.232.194.162
You can also combine record type with the -f option. The following example displays the MX records of multiple websites that are located in the names.txt file.
$ dig -f names.txt MX +noall +answer redhat.com. 600 IN MX 10 mx2.redhat.com. redhat.com. 600 IN MX 5 mx1.redhat.com. centos.org. 3600 IN MX 10 mail.centos.org.
Query multiple websites from dig command line:
You can also query multiple websites from the dig command line as shown below. The following example queries MX record for redhat.com,and NS record for centos.org from the command line
$ dig redhat.com mx +noall +answer centos.org ns +noall +answer; <<>> DiG 9.7.3-RedHat-9.7.3-2.el6 <<>> redhat.com mx +noall +answer centos.org ns +noall +answer
;; global options: +cmd
redhat.com. 332 IN MX 10 mx2.redhat.com.
redhat.com. 332 IN MX 5 mx1.redhat.com.
centos.org. 3778 IN NS ns3.centos.org.
centos.org. 3778 IN NS ns4.centos.org.
centos.org. 3778 IN NS ns1.centos.org.
10. Use $HOME/.digrc File to Store Default dig Options
If you are always trying to view only the ANSWER section of the dig output,you don’t have to keep typing “+noall +answer” on your every dig command. Instead,add your dig options to the .digrc file as shown below.
$ cat $HOME/.digrc +noall +answer
Now anytime you execute dig command,it will always use +noall and +answer options by default. Now the dig command line became very simple and easy to read without you have to type those options every time.
$ dig redhat.com redhat.com. 60 IN A 209.132.183.81$ dig redhat.com MX
redhat.com. 52 IN MX 5 mx1.redhat.com.
redhat.com. 52 IN MX 10 mx2.redhat.com.
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t kNow what these tools are and how to use them,you Could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools,which will help you to become an effective Linux system administrator
10 Questions To Make Programming Interviews Less Expensive--reference
decoration: underline;">10 Questions to Start Your Programming Interview
(Object Oriented Programming),my weed out question is Here I expect slightly more than the popular deFinition of classes are blue print to create objects,yes that's correct but how do you kNow that he understood the concept and not just have mugged it,Ask him to give examples,and then cross question him on that e.g. where does object get created,who creates it etc. ,particularly when it comes to code,the most popular question to weed out the non-programming programmer is . If a programmer cannot write a Fizz-buzz in 10 to 15 minutes,he probably needs more practice and not ready yet. This is something I don't ask on phone interview but on written test I have before face to face interviews. There has been instances in past before we had a proper interview process of multiple rounds where I had literally asked Fizzbuzz,and their answer took the better part of an hour. Another weed out question in my list for programming is to have them write and ask them to optimize it. Fibonacci is very common but you would be surprise with number of programmers failing to write in using pen and paper and even on IDE. It also weed out programmers who understand recursion than who doesn't. My experience is the programmer who understand recursion are usually better than those who doesn't. This is where most of natural programmers comes in.,my weed out question is Some one may say that it slightly harsh to judge someone's XML skill with just one question,but you would agree that this is a fundamental. I kNow there are many programmer who has worked in XML and can work in XML but doesn't familiar with this fundamental but shouldn't it's their responsibility to learn fundamental like this,just working is not enough,you also need to fill your gap.,my weed out question is It's such a fundamental that I expect anyone who has worked or learned Java should know about it. Here I expect that they should mention about some tools which comes with JDK,at least javac (the Java compiler) and JVM,which actually runs every Java program. One more question in my list to weed out non Java programmer is I have hard time teaching this fundamental to couple of people and have found that if you don't kNow difference between these two,you will struggle to set-up your project,debugging and fixing those nightmarish ClassNotFoundException and NoClassDefFoundError. It's again a must kNow detail for any one who claims to work in Java. be it in Java or any other language,one of the good weed out question is asking candidate to . You can ask this question differently either by giving him a practical scenario or just asking about how to code so that deadlock doesn't happen. If you have not done many interviews,you will be surprised with how many programmers,with professional experience of 2 to 4 years fail to answer this question correctly.,the first question I ask to candidate is about ,because I believe that as a programmer you must know array,linked list,set,map and string algorithms. If you want to add another level of cushion than you can also ask about without using any library function. This will give you enough idea whether to proceed further or not.
费波那契数列(:Successione di Fibonacci),又译费波拿契数、斐波那契数列、斐波那契数列、黄金分割数列。
在
-
(n≧2)
用文字来说,就是费波那契数列由0和1开始,之后的费波那契系数就由之前的两数相加。首几个费波那契系数是(
特别指出:不是第一项,而是第零项。
源自:http://zh.wikipedia.org/wiki/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97
15 Advanced PostgreSQL Commands with Examples
转自:http://www.thegeekstuff.com/2009/04/15-practical-postgresql-database-adminstration-commands/
1. 如何找到postgresql数据库中占空间最大的表?
$ /usr/local/pgsql/bin/psql test Welcome to psql 8.3.7,the Postgresql interactive terminal. Type: \copyright for distribution terms \h for help with sql commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit test=# SELECT relname,relpages FROM pg_class ORDER BY relpages DESC; relname | relpages -----------------------------------+---------- pg_proc | 50 pg_proc_proname_args_nsp_index | 40 pg_depend | 37 pg_attribute | 30
如果你只想要最大的那个表,可以用limit参数来限制结果的数量,就像这样:
# SELECT relname,relpages FROM pg_class ORDER BY relpages DESC limit 1; relname | relpages ---------+---------- pg_proc | 50 (1 row)
- relname- 关系名/表名
- relpages- 关系页数(默认情况下一个页大小是8kb)
- pg_class- 系统表,维护着所有relations的详细信息
- limit 1- 限制返回结果只显示一行
2. 如何计算postgresql数据库所占用的硬盘大小?
pg_database_size这个方法是专门用来查询数据库大小的,它返回的结果单位是字节(bytes)。:
# SELECT pg_database_size('geekdb'); pg_database_size ------------------ 63287944 (1 row)
如果你想要让结果更直观一点,那就使用**pg_size_pretty**方法,它可以把字节数转换成更友好易读的格式。
# SELECT pg_size_pretty(pg_database_size('geekdb')); pg_size_pretty ---------------- 60 MB (1 row)