【问题标题】:How to calculate how much memory for database I need?如何计算我需要多少数据库内存?
【发布时间】:2016-09-26 15:01:04
【问题描述】:

我正在创建一个带有数据库的应用程序。我为我的数据库找到了一些免费托管,但我不确定我的数据库是否有足够的内存。所以,我的问题是,如果我知道每个表有多少记录(行),如何计算硬盘上大约需要多少内存? PS:数据库不会有任何媒体(图片、音乐等)只有数字和文字。

【问题讨论】:

    标签: postgresql memory


    【解决方案1】:

    这是一个更经验性的答案,虽然不优雅,但应该为您提供一个起点。它基于this link

    1. Construct a dummy table that is set up **exactly** how you want your real table to be.
    
    2. Write a query that inserts 10000 random rows into the table.
       You can use a scripting language for this.
       For example, if you have three columns, all with varchar(100), try using php to write this query"
    
        $col1_Val = str_repeat('x', mt_rand(0,100));
        $col2_Val = str_repeat('y', mt_rand(0,100));
        $col3_Val = str_repeat('z', mt_rand(0,100));
    
        $bulk_query = "INSERT INTO my_dummy_table (col1, col2, col3) VALUES ($col1_Val, $col2_Val, $col3_Val),";
    
    3. Concatenate to create a statement that will do 10000 inserts:
        for($i = 0; $i < 9999; $i++) {
            $col1_Val = str_repeat('x', mt_rand(0,100));
            $col2_Val = str_repeat('y', mt_rand(0,100));
            $col3_Val = str_repeat('z', mt_rand(0,100));
            $bulk_query .= ",($col1_Val, $col2_Val, $col3_Val)";
        }
    
    4. Now the query has been constructed.
       Echo it or copy it in whichever way and then run the query from a script, PHPAdmin, command line, etc.
    
    5. Now get the table size either using the link above, PHPAdmin, etc.
    
    6. Divide the table size by 10000.
       This is your `average space requirement per row`.
    
    7. If you know roughly how many rows your table will need, multiply `number of rows` by `average space requirement per row`.
       This your **estimated space requirement**.
    

    【讨论】:

      猜你喜欢
      • 2011-05-24
      • 1970-01-01
      • 2020-04-04
      • 1970-01-01
      • 2013-08-08
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多