PostgreSQL的 initdb 源代码分析之二

本文详细解析了PostgreSQL中initdb命令的各个选项及其功能,包括数据目录设置、调试模式等,并介绍了如何通过这些选项定制数据库初始化过程。

继续分析

下面这一段,当 initdb --version 或者  initdb --help 才有意义。

复制代码
    if (argc > 1)
    {

        if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
        {
            usage(progname);
            exit(0);
        }
        if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
        {
            puts("initdb (PostgreSQL) " PG_VERSION);
            exit(0);
        }
    }
复制代码

再看下一段:

实际上就是 initdb 运行时候,后面可以跟各种参数。我这里只考虑 -D那种就好了

复制代码
    /* process command-line options */
    while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:sT:X:", long_options, &option_index)) != -1)
    {
        switch (c)
        {
            case 'A':
                authmethod = xstrdup(optarg);
                break;
            case 'D':
                pg_data = xstrdup(optarg);
                break;
            case 'E':
                encoding = xstrdup(optarg);
                break;
            case 'W':
                pwprompt = true;
                break;
            case 'U':
                username = xstrdup(optarg);
                break;
            case 'd':
                debug = true;
                printf(_("Running in debug mode.\n"));
                break;
            case 'n':
                noclean = true;
                printf(_("Running in noclean mode.  Mistakes will not be cleaned up.\n"));
                break;
            case 'L':
                share_path = xstrdup(optarg);
                break;
            case 1:
                locale = xstrdup(optarg);
                break;
            case 2:
                lc_collate = xstrdup(optarg);
                break;
            case 3:
                lc_ctype = xstrdup(optarg);
                break;
            case 4:
                lc_monetary = xstrdup(optarg);
                break;
            case 5:
                lc_numeric = xstrdup(optarg);
                break;
            case 6:
                lc_time = xstrdup(optarg);
                break;
            case 7:
                lc_messages = xstrdup(optarg);
                break;
            case 8:
                locale = "C";
                break;
            case 9:
                pwfilename = xstrdup(optarg);
                break;
            case 's':
                show_setting = true;
                break;
            case 'T':
                default_text_search_config = xstrdup(optarg);
                break;
            case 'X':
                xlog_dir = xstrdup(optarg);
                break;
            default:
                /* getopt_long already emitted a complaint */
                fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
                        progname);
                exit(1);
        }
    }
复制代码

也就是这段:

            case 'D':
                pg_data = xstrdup(optarg);
                break;











评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值