Python's sqlite3 library filled the free space c:\ drive
Python's sqlite3 library filled the free space c:\ drive
我正在为一家药店开发一个软件来跟踪药店的销售情况。我在 windows 10 上使用 VS Code 我决定制作一个玩具数据来测试软件。所以首先我在 sales.sqlite
数据库文件中创建了一个名为 sales
的 table。 table 有五列(time_stamp: INTEGER
、medications:REAL
、beauty:REAL
、total:REAL
、user:TEXT
)。然后我随机生成了 10000 个 Unix 时间戳并将它们存储在 timestamps.txt
文件中,以便稍后加载它们。之后,我执行了以下 python 代码,将我的玩具数据存储在 sales.sqlite
文件中的销售 table 中:
# load the timestamp and store them in a list
with open('timestamps.txt', 'r', encoding='utf-8') as f:
time_stamps = [int(stamp) for stamp in f.read().split('\n')]
# sort the timestamps
time_stamps.sort()
import random
# generate random values for each variable
medications = [random.randint(100, 5000) for i in range(10000)]
beauty = [random.randint(0, 5000) for i in range(10000)]
total = [medications[i] + beauty[i] for i in range(10000)]
user = [random.choice(['abosoar', 'abosoar1']) for i in range(10000)]
import sqlite3
# create entries by zipping the generated values of each variable
# Iterate over enteries and eatch time store one
for entry in zip(time_stamps, medications, beauty, total, user):
db = sqlite3.connect('databases\sales.sqlite')
c = db.cursor()
c.execute('INSERT INTO sales (time_stamp, medications, beauty, total, user) VALUES (?, ?, ?, ?, ?);', entry)
db.commit()
c.close()
db.close()
不到 30 秒后,IDE 崩溃了,我的 C:\ 驱动器的可用存储空间从 2.3+ GB 仅下降到 79 MB!
我 通过在 run
window 中键入 %temp%
和 temp
清理了临时文件,但我只恢复了 200 MB我的免费存储空间。
我使用了高级系统护理程序来删除垃圾文件,但我使用这种方法只恢复了 500 MB。
我注意到有一个名为 pagefile.sys
和 hiberfile.sys
的文件在代码 运行ning 时被修改了,它们的大小分别为 2.9 GB 和 1.6 GB 我想知道如果它们与问题之间有任何关系。
现在有两个问题:
首先:我无法释放 space sqlite 已占用
其次:软件应该在低 space PC 上运行,因此必须解决存储问题才能使软件 运行。
希望以上信息可以帮助解决我的问题。
当计算机没有足够的 RAM 来保存所有 运行 程序和数据时,它可能会尝试将磁盘上的一些信息移动到文件 pagefile.sys
- 稍后它可能会尝试取回它(什么时候程序需要它)。
类似地,当您在 hibernate
模式下关闭计算机时,它会将 RAM 保存在文件 hiberfile.sys
中,以便在您重新启动计算机时将其取回。如果您在 RAM 中有很多数据,那么它会在 hibernate.sys
.
中保存很多信息
如果您以正常方式重新启动计算机(没有 hibernate
或 sleep
模式)那么它可能会清除 pagefile.sys
- 或者您可以尝试删除它并且它应该重新创建它没有所有旧数据(正常重启后无法获取)。
至于我,您不会在此代码中创建那么多数据,但也许您的计算机对使用 [... for i in range(10000)]
创建的所有数据都有问题。如果您直接在主 for
-loop 中创建单个元素而不将所有元素都保存在内存中,则可以使用更少的 RAM。
我运行 for
-loop 只在内存中保留文件中的一行。它还在每个循环中只创建一个 medications, beauty, total, user
。
import sqlite3
import random
# --- before loop ---
db = sqlite3.connect('databases\sales.sqlite')
c = db.cursor()
# --- loop ---
for line in open('timestamps.txt'): #, encoding='utf-8'):
time_stamp = int(line)
medications = random.randint(100, 5000)
beauty = random.randint(0, 5000)
total = medications + beauty
user = random.choice(['abosoar', 'abosoar1'])
c.execute('INSERT INTO sales (time_stamp, medications, beauty, total, user) VALUES (?, ?, ?, ?, ?);', (time_stamp, medications, beauty, total, user)
db.commit()
# --- after loop ---
c.close()
db.close()
正如 furas 在他的回答中所说,解决方案是尽量减少内存中的数据量,这样它就不会备份 pagefile.sys
文件中的数据。
还要考虑以下 post:
https://smallbusiness.chron.com/reduce-pagefilesys-size-53940.html
这解决了这个问题(pagefile.sys
文件的巨大尺寸)。
我正在为一家药店开发一个软件来跟踪药店的销售情况。我在 windows 10 上使用 VS Code 我决定制作一个玩具数据来测试软件。所以首先我在 sales.sqlite
数据库文件中创建了一个名为 sales
的 table。 table 有五列(time_stamp: INTEGER
、medications:REAL
、beauty:REAL
、total:REAL
、user:TEXT
)。然后我随机生成了 10000 个 Unix 时间戳并将它们存储在 timestamps.txt
文件中,以便稍后加载它们。之后,我执行了以下 python 代码,将我的玩具数据存储在 sales.sqlite
文件中的销售 table 中:
# load the timestamp and store them in a list
with open('timestamps.txt', 'r', encoding='utf-8') as f:
time_stamps = [int(stamp) for stamp in f.read().split('\n')]
# sort the timestamps
time_stamps.sort()
import random
# generate random values for each variable
medications = [random.randint(100, 5000) for i in range(10000)]
beauty = [random.randint(0, 5000) for i in range(10000)]
total = [medications[i] + beauty[i] for i in range(10000)]
user = [random.choice(['abosoar', 'abosoar1']) for i in range(10000)]
import sqlite3
# create entries by zipping the generated values of each variable
# Iterate over enteries and eatch time store one
for entry in zip(time_stamps, medications, beauty, total, user):
db = sqlite3.connect('databases\sales.sqlite')
c = db.cursor()
c.execute('INSERT INTO sales (time_stamp, medications, beauty, total, user) VALUES (?, ?, ?, ?, ?);', entry)
db.commit()
c.close()
db.close()
不到 30 秒后,IDE 崩溃了,我的 C:\ 驱动器的可用存储空间从 2.3+ GB 仅下降到 79 MB!
我 通过在 run
window 中键入 %temp%
和 temp
清理了临时文件,但我只恢复了 200 MB我的免费存储空间。
我使用了高级系统护理程序来删除垃圾文件,但我使用这种方法只恢复了 500 MB。
我注意到有一个名为 pagefile.sys
和 hiberfile.sys
的文件在代码 运行ning 时被修改了,它们的大小分别为 2.9 GB 和 1.6 GB 我想知道如果它们与问题之间有任何关系。
现在有两个问题:
首先:我无法释放 space sqlite 已占用
其次:软件应该在低 space PC 上运行,因此必须解决存储问题才能使软件 运行。
希望以上信息可以帮助解决我的问题。
当计算机没有足够的 RAM 来保存所有 运行 程序和数据时,它可能会尝试将磁盘上的一些信息移动到文件 pagefile.sys
- 稍后它可能会尝试取回它(什么时候程序需要它)。
类似地,当您在 hibernate
模式下关闭计算机时,它会将 RAM 保存在文件 hiberfile.sys
中,以便在您重新启动计算机时将其取回。如果您在 RAM 中有很多数据,那么它会在 hibernate.sys
.
如果您以正常方式重新启动计算机(没有 hibernate
或 sleep
模式)那么它可能会清除 pagefile.sys
- 或者您可以尝试删除它并且它应该重新创建它没有所有旧数据(正常重启后无法获取)。
至于我,您不会在此代码中创建那么多数据,但也许您的计算机对使用 [... for i in range(10000)]
创建的所有数据都有问题。如果您直接在主 for
-loop 中创建单个元素而不将所有元素都保存在内存中,则可以使用更少的 RAM。
我运行 for
-loop 只在内存中保留文件中的一行。它还在每个循环中只创建一个 medications, beauty, total, user
。
import sqlite3
import random
# --- before loop ---
db = sqlite3.connect('databases\sales.sqlite')
c = db.cursor()
# --- loop ---
for line in open('timestamps.txt'): #, encoding='utf-8'):
time_stamp = int(line)
medications = random.randint(100, 5000)
beauty = random.randint(0, 5000)
total = medications + beauty
user = random.choice(['abosoar', 'abosoar1'])
c.execute('INSERT INTO sales (time_stamp, medications, beauty, total, user) VALUES (?, ?, ?, ?, ?);', (time_stamp, medications, beauty, total, user)
db.commit()
# --- after loop ---
c.close()
db.close()
正如 furas 在他的回答中所说,解决方案是尽量减少内存中的数据量,这样它就不会备份 pagefile.sys
文件中的数据。
还要考虑以下 post:
https://smallbusiness.chron.com/reduce-pagefilesys-size-53940.html
这解决了这个问题(pagefile.sys
文件的巨大尺寸)。